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

查看:612
本文介绍了使用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可以通知控制器(例如,通过事件)用户希望看到下一个View.控制器借助IoC容器创建View/ViewModel.

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)示例应用程序中显示了该方法的工作原理 .

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

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

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