使用MVVM从WPF应用程序启动对话框/子窗口的标准方法 [英] Standard Approach of Launching Dialogs/Child Windows from a WPF Application using MVVM

查看:245
本文介绍了使用MVVM从WPF应用程序启动对话框/子窗口的标准方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有,我想知道使用MVVM模式从WPF启动[child]对话框/窗口的公认的最佳方法/行业标准。我遇到了以下文章:



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



这种方法似乎很好,但对我来说过多。这是一定程度的代码复制,我不相信这是正确的方法。



B。 WPF MVVM和显示对话框



这个简单的经历了三个选项,各种链接在解释方法论或者主题方面都是非常/非常差的。



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



感谢你的时间。

解决方案

首先,我不知道使用MVVM显示对话框的任何行业标准方式,因为没有这样的东西。

其次欢迎来到MVVM,你刚刚谈到了MVVM没有标准的领域。

为了说实话,MVVM有很多痛点,这就是为什么有大量的MVVM框架在那里,只是提到几个MVVM Light,PRISM,Caliburn.Micro,Cinch,Catel,WAF,Baboon,shell我停止,或者你想要更多。

现在回答你的问题,在处理最多我注意到一个共同点,他们都使用一个DI / IoC容器,然后为您提供一个接口,像IDialogManager和它们自己的实现,然后他们要求你在你的视图模型中接受这个界面,并使用它来显示对话框。所以总结一下,我会使用依赖注入,有一个用于显示对话框的界面,然后提供和实现,并将其注册到di容器,然后从我的视图模型或视图中使用它。

编辑所以你选择了PRISM (这在我看来)之间是最显着的对话框之间。现在这是一个很难的方法是使用互动请求 (检查文章的中间),或者您可以使用此答案作为一种更快捷的方式。


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 - Showing Dialogs When Using the MVVM Pattern

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 and Showing Dialogs

This briefly runs through three options with various links which are all fairly/very poor at explaining the methodology or are of-topic.

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!

Thanks for your time.

解决方案

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 (check the middle of the article), or you can use this Answer as a quicker way.

这篇关于使用MVVM从WPF应用程序启动对话框/子窗口的标准方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆