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

}
相关推荐
冷眼Σ(-᷅_-᷄๑)24 分钟前
WPF缩放动画和平移动画叠加后会发生什么?
wpf·动画
△曉風殘月〆3 小时前
WPF MVVM入门系列教程(二、依赖属性)
c#·wpf·mvvm
.net开发10 小时前
WPF怎么通过RestSharp向后端发请求
前端·c#·.net·wpf
九鼎科技-Leo10 小时前
WPF 中 NavigationWindow 与 Page 的继承关系解析
wpf
SongYuLong的博客11 小时前
C# WPF 打印机
wpf
就是有点傻11 小时前
WPF中的转换器
wpf
.net开发18 小时前
WPF使用prism框架发布订阅实现消息提示
c#·.net·wpf
那少年已不再......1 天前
C#WPF使用CommunityToolkit.Mvvm库
开发语言·c#·wpf
SEO-狼术1 天前
Syncfusion Essential Studio WPF 2024 Crack
wpf
Olivia_vivi2 天前
WPF XAML
ui·wpf