使用 EventAggregator 在 ElementHost 中的 WPF 和宿主 WinForm 之间进行通信 [英] Using EventAggregator to communicate between WPF in ElementHost and host WinForm

查看:26
本文介绍了使用 EventAggregator 在 ElementHost 中的 WPF 和宿主 WinForm 之间进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 EventAggregator 订阅从 ViewModel 发布的 WinForm?

Can I use the EventAggregator to subscribe to events in a WinForm published from a ViewModel?

我需要将 WPF 复合应用程序的模块中在 ElementHost 中承载 WPF 复合应用程序的 WinForm 的属性更改为 此处描述.

I need to change the properties of a WinForm that hosts a WPF composite application in an ElementHost from a module of the WPF composite application as described here.

我认为要解决这个问题,我可以使用 EventAggregator 在 ViewModel 中发布事件,该事件将由 WinForm 订阅.此事件的参数可能包括我想在 WinForm 上更改的内容,例如标题.

I thought that to solve this problem I could use the EventAggregator to publish events in a ViewModel that would be subscribed to by the WinForm. The arguments of this event could include the things I want to change on the WinForm like the title.

我已阅读以下内容:

http://msdn.microsoft.com/en-us/library/ff921173%28v=PandP.40%29.aspx

http://www.codeproject.com/Articles/355473/Prism-EventAggregator-Sample

http://msdn.microsoft.com/en-us/library/ff649187.aspx

但我仍然无法确定 EventAggregator 是否适合这种情况.

But I still can't work out if the EventAggregator is fit for purpose in this situation.

推荐答案

如果所有这些组件都在同一个进程中,那么是的,您可以使用 EventAggregator.

If all of these components are in the same process then yes, you can use the EventAggregator.

请记住,您必须在发布者和订阅者中引用相同的聚合器实例 - 聚合器应该是单例,或者作为单例放入 IoC 容器中.

Just remember that you'd have to reference the same instance of the aggregator in the publisher and the subscriber - the aggregator should be a singleton or be put in an IoC container as a singleton.

这篇关于使用 EventAggregator 在 ElementHost 中的 WPF 和宿主 WinForm 之间进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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