wpf prism当中 发布订阅 IEventAggregator

先订阅后发布

csharp 复制代码
private readonly IEventAggregator _eventAggregator;
public LoginViewModel(ILoginService iloginService, IEventAggregator eventAggregator)
{
    _iloginService = iloginService;
    _eventAggregator = eventAggregator;

    _eventAggregator.GetEvent<MessageEvent>().Subscribe(Reviced);
    UserName = "admin";
    PassWord = "123456";

    LoginCommand = new DelegateCommand<object>(DoLogin);


}

private void Reviced(string obj)
{
    throw new NotImplementedException();
}
csharp 复制代码
 private readonly IEventAggregator _eventAggregator;
 public LeftMenuViewModel(IRegionManager regionManager, IUnityContainer unityContainer, IMenuService menuService, IEventAggregator eventAggregator)
 {
     _eventAggregator = eventAggregator;
     _regionManager = regionManager;
     _menuService = menuService;
     origMenus = unityContainer.Resolve<GlobalValue>().UserInfo.Menus;

     var AllMenusList = menuService.GetAllMenus();
     var str = JsonHelper.SerializerToJsonString(AllMenusList);
     origMenus = JsonHelper.DeserializerJsonResult<List<SysMenu>>(str);
    
     eventAggregator.GetEvent<MessageEvent>().Publish("hello_ok");
     // 通过接口获取 菜单 数据   
     //origMenus = await menuBLL.GetMenus(0);// 通过接口获取 菜单 数据       
     // 需要初始化的进候进行菜单数据的获取填充
     // 通过Api接口

     //Task.Run(async () =>
     //{
     //    origMenus = unityContainer.Resolve<GlobalValue>().UserInfo.menus;
     //    origMenus = await menuBLL.GetMenus(0);// 通过接口获取 菜单 数据       

     //    unityContainer.Resolve<Dispatcher>().Invoke(() =>
     //    {
     //        this.FillMenus(Menus, 0);
     //    });
     //});
     FillMenus(Menus, 0);
 }
csharp 复制代码
using Prism.Events;

public class MessageEvent : PubSubEvent<string>
{

}
相关推荐
不会编程的懒洋洋1 天前
WPF 性能优化+异步+渲染
开发语言·笔记·性能优化·c#·wpf·图形渲染·线程
求学中--2 天前
状态管理一文通:@State、@Prop、@Link、@Provide/Consume全解析
人工智能·小程序·uni-app·wpf·harmonyos
雨浓YN3 天前
GKTGD 工业监控系统-00设计文档
wpf
秋の本名4 天前
第一章 鸿蒙生态架构与开发理念
华为·wpf·harmonyos
Bofu-4 天前
【音频测试】03-WPF 实现声道自动验证 + Whisper 语音识别录音检测
c#·whisper·wpf·音视频·音频测试·naudio 声道控制
秋の本名4 天前
DevEco Studio 版本演进揭秘:从3.0到5.0的分布式开发能力飞跃与智能体验革新
wpf·鸿蒙系统
heimeiyingwang6 天前
【架构实战】状态机架构:订单/工单状态流转设计
观察者模式·架构·wpf
KmSH8umpK8 天前
Redis分布式锁从原生手写到Redisson高阶落地,附线上死锁复盘优化方案进阶第三篇
redis·分布式·wpf