棱镜,事件发布在外壳没有被抓住模块! [英] Prism, Event published in shell not caught in module!

查看:126
本文介绍了棱镜,事件发布在外壳没有被抓住模块!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wpf复合应用程序,3或4个模块将始终加载。在我的shell中,我有一个带有按钮的工具栏来激活这些模块的相应视图。我将一个IEventAggregator注入到shell演示器中,这样当按下一个按钮时,我可以发布相应的模块控制器订阅的事件。当事件被捕获时,控制器将激活其视图。



无论如何,无论如何,在实践中,我的控制器捕获事件。发布或订阅没有错误。我首先想到可能是一个问题,eventAggregator不一样,但事实并非如此,事件有一个订阅者发布时。



可以有人想到为什么事件没有被抓住的原因?
(或任何建议以不同的方式让我的观点显示也将是有帮助的。)

解决方案

你的模块控制器活着吗?您是否使用弱代理引用或强引用订阅事件?
似乎正在发生的是你的模块控制器被处理,所以事件没有被捕获。



要订阅一个强有力的参考,请使用订阅方法中的 keepSubscriberReferenceAlive 选项。



您可以查看事件聚合从文档中可能提供更多洞察的文章。



如果还是不行,你能和我分享你的复制代码,所以我可以看看吗? (ezequieljadib at hotmail dot com)



谢谢,



Ezequiel Jadib


I have a wpf composite application with 3 or 4 modules that will always be loaded. In my shell I have a toolbar with buttons to active corresponding views from these modules. I injected an IEventAggregator into the shell presentor so that when a button is pressed I can publish an event that the corresponding module controller has subscribed to. When the event is caught the controllor will active its view.

Thats the theory anyways, in practice my controller is not catching the event. There are no errors in publishing or subscribing. I thought at first that there might be an issue with the eventAggregator not being the same, but thats not the case, and the event has a subscriber when its published.

Can anyone think of a reason why the event is not getting caught? (Or any suggestions on a different way to get my view to show would be helpful too!)

解决方案

Do you have your module controller 'alive'? Are you subscribing to the event using weak delegate reference or strong reference? Seems that what is happening is that your module controller is being disposed, and so, the event is not getting caught.

To subscribe with a strong reference, use the keepSubscriberReferenceAlive option on the Subscribe method.

You can check the Event Aggregator article from the documentation which might provide more insight.

If that still does not works, can you share your repro code with me so I can take a look to it? (ezequieljadib at hotmail dot com)

Thanks,

Ezequiel Jadib

这篇关于棱镜,事件发布在外壳没有被抓住模块!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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