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

}
相关推荐
beyond谚语6 小时前
第一章 WPF概述
wpf
necessary6531 天前
从工行“余额归零”事件看CAP定理:当金融系统在一致性与可用性之间做出选择
分布式·金融·wpf·可用性测试
棉晗榜1 天前
WPF隐藏控件后,怎么让其上部的控件空间自动撑高
wpf
壹佰大多2 天前
【Redisson分布式锁源码分析-3】
数据结构·分布式·mysql·spring·spring cloud·wpf·lua
LateFrames2 天前
以小白视角尝试 WPF / WinUI3 / MAUI / MAUI Blazor 构建 Windows 桌面程序
windows·wpf·maui·mauiblazor·winui3
偶尔的鼠标人3 天前
Avalonia/WPF 打开子窗口,并且跨页面传值
c#·wpf·mvvm·avalonia
玖笙&3 天前
✨WPF编程进阶【6.1】:图形原则(附源码)
c++·c#·wpf·visual studio
lixy5793 天前
WPF检测网络状态切换
wpf
纸照片3 天前
WPF中为Button设置IsMouseOver和IsPressed事件中改变背景颜色不起作用
c#·.net·wpf
Aevget3 天前
DevExpress WPF中文教程:Data Grid - 如何使用虚拟源?(四)
ui·.net·wpf·devexpress·wpf控件