所有,我想知道使用 MVVM 模式从 WPF 启动 [子] 对话框/窗口的公认最佳方法/行业标准.我遇到过以下文章:
All, I would like to know the recognised best approach/industry standard of launching [child] dialogs/windows from an WPF using the MVVM pattern. I have come across the following articles:
A.CodeProject - 使用 MVVM 模式时显示对话框一个>
这种方法看起来不错,但对我来说太过分了.这是某种程度的代码复制,我不相信这是正确的方法.
This approach seems good but excessive to me. The is some degree of code replication and I am not convinced this is the right way to go.
B.WPF MVVM 和显示对话框
这简要介绍了三个选项,其中包含各种链接,这些链接在解释方法方面都相当/非常差或与主题无关.
This briefly runs through three options with various links which are all fairly/very poor at explaining the methodology or are of-topic.
有人可以解释行业标准使用 MVVM 从 WPF 应用程序启动对话框的方法/方法,最好是一些指向进一步阅读材料的链接?如果你能自己提供一个例子,我当然会非常感激!
Can someone please provide an explanation of the industry standard method/approach of launching dialogs from a WPF application using MVVM and preferably some links to further reading material? If you can provide an example yourself I would of course be most appreciative!
感谢您的宝贵时间.
首先,我不知道任何使用 MVVM 显示对话框的行业标准"方式,因为没有这样的东西.
其次,欢迎使用 MVVM,您刚刚谈到了 MVVM 没有标准的领域.
说实话,MVVM 有很多痛点,这就是为什么有大量 MVVM 框架存在的原因,仅举几个 MVVM Light、PRISM、Caliburn.Micro、Cinch、Catel、WAF、Baboon、shell i停下来,或者你想要更多.
现在回答你的问题,在处理了大多数框架之后,我注意到一个共性,它们都使用 DI/IoC 容器,然后为你提供一个接口,比如 IDialogManager 和他们自己的实现,然后他们问你在您的视图模型中接受此接口并使用它来显示对话框.所以总结一下,我会使用依赖注入,有一个显示对话框的接口,然后提供和实现它,并将它注册到 di 容器,然后从我的视图模型或视图中使用它.
所以您选择了 PRISM(在我看来) 在显示对话框方面是它们中最难的.撇开这一点不谈,还有一个困难的方法是使用 交互请求 (查看文章中间),或者你可以使用这个回答作为一种更快的方式.
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.
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 (check the middle of the article), or you can use this Answer as a quicker way.
这篇关于使用 MVVM 从 WPF 应用程序启动对话框/子窗口的标准方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!