WPF Viewmodel通讯 [英] WPF Viewmodel communication

查看:122
本文介绍了WPF Viewmodel通讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将MVVM模式与WPF配合使用.我有一个主窗口. Mainwindow有一个视图模型.单击主窗口上的按钮可打开模态"对话框.在此模式对话框中,有一个用户控件.该用户控件也有一个视图模型.当我更改用户控件中的属性时,如何使主窗口知道更改.
我不了解主窗口的视图模型与模式对话框之间的通信.
谢谢

I am using MVVM pattern with WPF. I have a mainwindow. Mainwindow has a viewmodel. A button click on the mainwindow opens a Modal dialog. In this Modal dialog there is a user control. This usercontrol also has a viewmodel. When I change a property in the Usercontrol, how can i make the main window aware of the change.
I do not understand the communication between the viewmodels of mainwindow and the modal dialog.
Thanks

推荐答案

一种方法是使用事件聚合器 [ ^ ].

何时使用事件聚合器,何时不使用始终是值得商topic的话题.
One way to do this could be by using event aggregators[^].

When to use an event aggregator and when not is always a debatable topic though.


这篇关于WPF Viewmodel通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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