先订阅后发布
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>
{
}