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>
{

}
相关推荐
旋生万物7 小时前
【终极实战】用Python从零“生成“一个宇宙:螺旋干涉模型的代码实现
开发语言·前端·人工智能·react.js·php·wpf
Now喔12 小时前
WPF画刷介绍
wpf
李高钢18 小时前
WPF/WinForms 客户端通过 gRPC 与后端通信:从 Proto 契约到流式调用的完整指南
wpf·grpc·winforms
一见已难忘2 天前
基于 Harmony 6.0 应用的宠物寄养预约系统实现
wpf·宠物
fl1768312 天前
基于C#WPF实现的内存加速球清理类似360加速球内存清理
开发语言·c#·wpf
李高钢2 天前
【WPF】高级 UI 与性能优化实战:从卡顿到丝滑
ui·性能优化·wpf
Chris _data2 天前
WPF 上位机开发学习笔记 - 第四天
笔记·学习·wpf
李高钢2 天前
除了 IDE,C#/WPF 开发者每天离不开的 10 个工具
ide·c#·wpf
李高钢3 天前
用 JetBrains Rider 写 WPF 的 15 个高效技巧:从 VS 转过来也值得看
wpf
李高钢3 天前
【WPF】MVVM 与数据绑定实战:从原理到完整项目
wpf