问题描述
使用Prism的EventAggregator`
可能会出现事件函数没有被触发调用的问题。
原因分析:
事件可能被C#垃圾回收了。
Prism官方的说明:
“keepSubscriberReferenceAlive” When langword=“true”, the cref=“PubSubEvent{TPayload}” keeps a reference to the subscriber so it does not get garbage collected.
解决方案:
keepSubscriberReferenceAlive参数设置为true,默认为false。
//订阅事件
ea.GetEvent<StationChangedEvent>().Subscribe(StationChanged,true);