使用 WPF MVVM 模式打开新窗口的最佳实践 [英] Best practices for opening a new window with WPF MVVM pattern

查看:29
本文介绍了使用 WPF MVVM 模式打开新窗口的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道这个问题......从另一个视图模型打开一个新窗口(视图和视图模型)的最佳实践是什么如果我们记住打开新窗口的视图模型不知道该观点的存在(应该如此).

I've been wondering about this for a while... What's the best practice for opening a new window (view & viewmodel) from another viewmodel IF we keep in mind that the viewmodel which opens the new window is not aware of the existence of that view (as it should be).

谢谢.

推荐答案

我不使用 ViewModel 打开另一个 View/ViewModel.这是控制器的责任.ViewModel 可以通知 Controller(例如通过 Event)用户希望看到下一个 View.控制器在 IoC 容器的帮助下创建视图/视图模型.

I don't use the ViewModel to open another View/ViewModel. This is in the responsibility of a Controller. The ViewModel can inform the Controller (e.g. via Event) that the user expects to see the next View. The Controller creates the View/ViewModel with the help of an IoC Container.

WPF 应用程序框架 (WAF) 的 ViewModel (EmailClient) 示例应用程序展示了其工作原理a>.

How this works is shown in the ViewModel (EmailClient) sample application of the WPF Application Framework (WAF).

这篇关于使用 WPF MVVM 模式打开新窗口的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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