wpf 在 MVVM 中以对话框形式打开窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13188570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 06:02:10  来源:igfitidea点击:

Open window as Dialog in MVVM

wpfmvvmdialog

提问by Harry

Hi Team,
I was following the sample MVVM WPF application from msdn. Everything seems tobe fine and closely a good sample to follow, but I was looking for opening a child window as Dialog from Menu -->open and thought a text input assing the input control to my child window tab and to the text control in usercontrol customer add, but couldn't find a solution. http://msdn.microsoft.com/en-us/magazine/dd419663.aspxlink for the source any help on this would be of gr8 help.

嗨团队,
我正在关注来自 msdn 的示例 MVVM WPF 应用程序。一切似乎都很好,并且是一个很好的示例,但我一直在寻找从菜单中打开一个作为对话框的子窗口 --> 打开并认为文本输入将输入控件分配给我的子窗口选项卡和用户控件中的文本控件客户添加,但找不到解决方案。http://msdn.microsoft.com/en-us/magazine/dd419663.aspx源链接的任何帮助都将是 gr8 帮助。

回答by yo chauhan

Window1 win1 = new Window1();
        win1.ShowDialog();

Window1 is the child window.This is a way to make child window to act as Dialog. If you want something like to fire Command from Parent window UI to its ViewModel then this ViewModel send message to its .xaml.cs file and then open Child window as dialog then go through MVVM Light API's. They provide way for communication from ViewModel to View.Go through this only if you want to follow strict MVVM pattern otherwise you can directly fire event from UI. I hope this will give you an idea.

Window1 是子窗口。这是一种使子窗口充当Dialog 的方法。如果您想从父窗口 UI 向其 ViewModel 发出命令,则此 ViewModel 将消息发送到其 .xaml.cs 文件,然后将子窗口作为对话框打开,然后通过 MVVM Light API。它们提供了从 ViewModel 到 View 的通信方式。仅当您想遵循严格的 MVVM 模式时才通过此方法,否则您可以直接从 UI 触发事件。我希望这会给你一个想法。

回答by blindmeis

hereis an easy way to have dialog with mvvm.

是与 mvvm 进行对话的简单方法。

all you have to call in your viewmodel is:

您只需在视图模型中调用:

var result = this.uiDialogService.ShowDialog("Dialogwindow title goes here", dialogwindowVM);