我已经使用Menu控件在我的应用程序中实现了导航,该控件在单击菜单项时使用EventAggregator发布事件。如下所示,
this.eventAggregator.GetEvent<ViewRequestedEvent>()
.Publish(new BusinessObject.Model.MenuModel
{
Module = "Dashboard",
PresenterClass = "DashboardViewModel"
});
我的应用程序中的大多数模块都是此事件的订阅者。他们使用过滤器仅订阅与模块相关的事件
this.eventAggregator.GetEvent<ViewRequestedEvent>()
.Subscribe(LoadViewRequest, ThreadOption.UIThread, true, i => i.Module == "Dashboard");
请求视图的处理方式如下:
private void LoadRequestedView(MenuModel menuItem)
{
try
{
IDashboardViewModel viewModel = this.container.Resolve(Type.GetType(menuItem.PresenterClass)) as IDashboardViewModel;
this.regionManager.Regions["ViewRegion"].Add(viewModel.View);
this.regionManager.Regions["ViewRegion"].Activate(viewModel.View);
this.eventAggregator.GetEvent<ViewNotificationEvent>().Publish(menuItem.Description);
}
catch (ResolutionFailedException) { }
}
您如何评价此实施?如果你觉得它很糟糕,请帮助我改进它或建议一个更好的选择。
答案 0 :(得分:0)
我认为你对这种模式的关注点有一定的不足。我一般都试图向壳牌公司提交报告。请参阅此问题,了解我如何实现此目的。它简化了事物并将RegionManager的概念从模块中抽象出来:
Integrating Modules with Application in Prism aka CompositeWpf