使用MVVM从WPF应用程序启动对话框/子窗口的标准方法

Moo*_*ght 10 c# wpf dialog mvvm

总而言之,我想知道使用MVVM模式从WPF启动[子]对话框/窗口的公认最佳方法/行业标准.我遇到过以下文章:

A. CodeProject - 使用MVVM模式时显示对话框

这种做法看起来不错,但对我来说太过分 这是一定程度的代码复制,我不相信这是正确的方法.

B. WPF MVVM和显示对话框

这简要地介绍了三个选项,其中包含各种链接,这些链接在解释方法或主题方面都相当/非常差.

有人可以提供使用MVVM从WPF应用程序启动对话框的行业标准方法/方法的解释,最好是一些链接到进一步的阅读材料吗?如果你能自己提供一个例子我当然会非常感激!

谢谢你的时间.

Ibr*_*jar 9

First of all, i don't know of any "industry-standard" way for showing dialogs using MVVM because there is no such thing.
Secondly, Welcome to MVVM, you have just touched on of the areas that MVVM don't have a standard for.
To tell you the truth, MVVM has many pain points and this is the reason why there are tons of MVVM frameworks out there, just to mention a few MVVM Light, PRISM, Caliburn.Micro, Cinch, Catel, WAF, Baboon, shell i stop or you want more.
Now to answer your question and after dealing with most of those frameworks, i noticed one commonality, they all use a DI/IoC container and then provide you with an interface, something like IDialogManager and an implementation of their own, and then they ask you to accept this interface in your view model and use it to show dialogs. So to sum this up, i would use dependency injection, have an interface for showing dialogs, and then provide and implementation of that, and register it with the di container and then consume it from my view model or views.
Edit: So you have picked PRISM (which in my opinion) is hardest between them all in showing dialogs. Now that's aside, there is the hard way which is by using Interaction Requests (查看文章的中间部分),或者您可以使用此答案作为一种更快捷的方式.