wpf prism 《4》 事件 发布订阅 对话服务 Dialog

发布时间:2026/9/11 10:13:42
wpf prism 《4》 事件 发布订阅 对话服务 Dialog EventAggregator事件聚合器toolkit mvvmEventAggregator事件聚合器。它像一个应用内部的“消息广播站”让不同模块或 ViewModel之间无需直接引用就能通过事件进行通信是实现松耦合的关键用两个窗体 模拟发布订阅# 1、定义事件#事件通常定义在共享项目以便所有模块都能引用usingPrism.Events;// 无参数事件publicclassGlobalEmergencyStopEvent:PubSubEvent{}// 带字符串参数的事件publicclassTickerSymbolSelectedEvent:PubSubEventstring{}// 带自定义对象参数的事件 AlarmItem 是一个类publicclassAlarmOccurredEvent:PubSubEventAlarmItem{}# 2、订阅事件# 3、发布事件》》》订阅的参数》》》具体案例情况PubSubEvent 继承 EventBaseTEventType GetEvent() where TEventType : EventBase, new();