当我单击一个按钮时,我正在尝试实现一个弹出窗口。我希望将按钮绑定(bind)到我的 ViewModel 中的 RelayCommand,并且我希望从这个 RelayCommand 添加我的 PopUp。弹出窗口是在 View(xaml) 中制作的。我正在为 Windows 手机使用 MVVM 模型。我的弹出窗口的 View (xaml)是:
<Popup>
<Border Background="Blue">
<TextBlock Text="Hej med dig" FontSize="25"/>
</Border>
</Popup>
我的 Button 的 View(xaml) 是
<Button BorderBrush="Transparent" BorderThickness="0" Command="{Binding ClickCommand}" CommandParameter="{Binding}">
<Button.Template>
<ControlTemplate>
<Path x:Name="CountryUser" Stretch="Fill" StrokeThickness="{StaticResource StrokeUserControl}" StrokeLineJoin="Round" Fill="{StaticResource CountryBackground}" Stroke="{Binding CountryView.CountryColor}" Data="{Binding CountryView.MapData}"/>
</ControlTemplate>
</Button.Template>
</Button>
绑定(bind)到我的 Button 的 ViewModel(C#),我希望从其中添加 RelayCommand,它在单击我的按钮时激活 Popup 是:
public ICommand ClickCommand { get; set; }
public CountryViewModel()
{
ClickCommand = new RelayCommand(Click);
}
public void Click()
{
PopUpUC TextPopUp = new PopUpUC();
}
我的问题是当我单击弹出窗口未显示的按钮时,任何帮助都会很好。
最佳答案
在 xaml 中,您应该将某些内容绑定(bind)到 IsOpen 属性,以便:
<Popup IsOpen="{Binding PopUpUCIsOpen}">
<Border Background="Blue">
<TextBlock Text="Hej med dig" FontSize="25"/>
</Border>
然后在点击中更改变量。
关于c# - 单击按钮时弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19857448/