【问题标题】:What is the best method to load Views dynamically from a Navigation control in Prism从 Prism 中的导航控件动态加载视图的最佳方法是什么
【发布时间】:2009-11-05 04:54:02
【问题描述】:

我已经使用菜单控件在我的应用程序中实现导航,该控件在单击菜单项时使用 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) { }
}

您如何评价此实施?如果您认为它很糟糕,请帮助我改进它或提出更好的替代方案。

【问题讨论】:

    标签: c# wpf prism eventaggregator


    【解决方案1】:

    我认为您对这种模型的关注点分离有一定的不足。我通常会尝试将演示文稿保留给 Shell。请参阅这个问题,了解我将如何实现这一点。它简化了事情并将 RegionManager 的概念从模块中抽象出来:

    Integrating Modules with Application in Prism aka CompositeWpf

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多