如何在WPF MVVM中实现ViewModel之间的通信 [英] How to achieve communication between ViewModels in WPF MVVM

查看:1340
本文介绍了如何在WPF MVVM中实现ViewModel之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,
在我看来,我有一个DataGrid和一个用户控件,它们都使用两个不同的ViewModel.我的用户控件还包含一个DataGrid.当我在任一ViewModel的DataGrid中添加新行时,它应通知另一个ViewModel或更好地将新添加的DataRow传递给另一个ViewModel.我该如何实现.

谢谢与问候,
Ramana


In my view I have a DataGrid and a usercontrol, both are using two different ViewModels. My user control also contains a DataGrid. When I add a new row to my DataGrid in any one of the ViewModel, it should notify the other ViewModel or better pass the newly added DataRow to the other ViewModel. How can I achieve this.

Thanks & Regards,
Ramana

推荐答案

您可以使用Marlon的 EventAggregator [^ ]来自Microsoft的PRISM框架.如果您使用Google for Mediator/EventAggregator,会获得大量使用示例.
You could use Marlon''s Mediator[^] or EventAggregator[^] from Microsoft''s PRISM Framework. If you Google for Mediator/EventAggregator you get loads of samples on how to use them.


这篇关于如何在WPF MVVM中实现ViewModel之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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