我已经通过我的应用程序中使用其发布的菜单项的点击使用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) { }
}

您如何评价这种实现?如果你认为它很烂,帮我改进或建议一个更好的选择。

有帮助吗?

解决方案

我觉得你有一定的缺乏与此模型关注点分离。我一般尽量保持呈现给壳牌。请参阅我如何尔德实现这个这个问题。它简化了的东西,并从模块抽象一个RegionManager的想法远:

集成与应用模块在棱镜又名CompositeWpf

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top