如何通过命令打开新窗口或用户控件 [英] How to open a new window or user control through command
问题描述
在我的WPF应用程序中,我有一个父窗口Main.xaml,我有一个按钮。单击按钮我想打开一个新窗口ChildWindow.xaml通过命令(而不是通过代码后面的点击事件)
当子窗体打开时我想禁用Main.xaml窗口,以便用户无法点击它上面的任何内容。
我需要通过MVVM,所以在我不想要的viewmodel中创建ChildWindow实例。有人可以帮帮我。
谢谢。
< b>我尝试了什么:
我可以通过代码behined实现它但我正在寻找使用MVVM
Hi,
In my WPF application, I have a parent window Main.xaml where i have a button. On click of button i want to open a new window ChildWindow.xaml through command (and not through click event in code behind)
when the child form open I want to disable the Main.xaml window so that user cannot click anything on it.
I need it through MVVM so creating ChildWindow instance in the viewmodel I am not looking for. Can anybody please help me out.
Thanks.
What I have tried:
I am able to acheive it through code behined but I am looking through using MVVM
推荐答案
您可以使用RelayCommand()
和
$ b将按钮绑定到命令$ b使用Application.Current.MainWindow
属性从ViewModel打开子窗口,将新子窗口链接到现有的MainWindow。
You can bind your button to a command usingRelayCommand()
and
have the child Window being opened from the ViewModel using theApplication.Current.MainWindow
property to link your new child window to the existing MainWindow.
这篇关于如何通过命令打开新窗口或用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!