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

}
相关推荐
CSharp精选营2 小时前
都是微软亲儿子,WPF凭啥干不掉WinForm?这3个场景说明白了
c#·wpf·跨平台·winform
baivfhpwxf20232 小时前
wpf TextBlock 控件如何根据内容换行?
wpf
亘元有量-流量变现3 小时前
鸿蒙、安卓、苹果音频设备技术深度解析与开发实践
android·wpf·harmonyos·亘元有量·积分墙
软泡芙3 小时前
【Bug】ReactiveUI WPF绑定中依赖属性不更新的问题分析与解决方案
java·bug·wpf
浪扼飞舟3 小时前
WPF输入验证(ValidationRule)
java·javascript·wpf
IOFsmLtzR2 天前
Flink Agents 源码解读 --- (5) --- ActionExecutionOperator
microsoft·flink·wpf
廋到被风吹走3 天前
【AI】Codex 复杂任务拆解:从“一气呵成“到“步步为营“
人工智能·wpf
希望永不加班3 天前
SpringBoot 整合 Redis 缓存
spring boot·redis·后端·缓存·wpf
_MyFavorite_3 天前
JAVA重点基础、进阶知识及易错点总结(29)JDK8 时间 API 进阶
java·开发语言·wpf
武藤一雄4 天前
深入拆解.NET内存管理:从GC机制到高性能内存优化
windows·microsoft·c#·.net·wpf·.netcore·内存管理