c# - 单击按钮时弹出

标签 c# xaml mvvm windows-phone-8 popup

当我单击一个按钮时,我正在尝试实现一个弹出窗口。我希望将按钮绑定(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/

相关文章:

c# - 如何在 Property Trigger 触发时设置 viewmodel 属性

c# - 包含项目更改时触发的 ObservableCollection

wpf - MVVM和Prism v2有什么区别

c# - 使用静态 NavigateTo<T> 方法在 Xamarin.Forms 中导航时如何传递参数?

c# - C#-程序添加一个额外的'找到'的地方

wpf - 我可以在运行时将 XML/XAML 转换为 WPF 控件吗?

c# - 递归搜索目录中的文件

java - Android RecyclerView 项目点击不起作用 - MVVM

c# - 在某些地方防止 GC 收集以提高性能

c# - C#多线程服务器-通用客户端集合可能是一个问题