什么是从棱镜导航控件动态加载次数的最佳方法 [英] What is the best method to load Views dynamically from a Navigation control in Prism

查看:243
本文介绍了什么是从棱镜导航控件动态加载次数的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过我的应用程序使用的发布对菜单项的点击使用EventAggregator事件的菜单控件实现导航功能。喜欢的东西,如下图所示,

I've implemented navigation through my application using a Menu control which publish an event using EventAggregator on click of menu item. Something like as shown below,

this.eventAggregator.GetEvent<ViewRequestedEvent>()
                    .Publish(new BusinessObject.Model.MenuModel
                    {
                        Module = "Dashboard",
                        PresenterClass = "DashboardViewModel"
                    });



大多数我的应用程序的模块是用户本次活动。他们使用过滤器来只订阅相关的模块

Most of the Modules in my application are subscriber to this event. They use a filter to subscribe only those events relevant to the Module

this.eventAggregator.GetEvent<ViewRequestedEvent>()
            .Subscribe(LoadViewRequest, ThreadOption.UIThread, true, i => i.Module == "Dashboard");



征求看法是这样处理的:

Request for View is handled like this:

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



如何您对此执行?如果你认为它很烂,帮助我提高,或提出一个更好的选择。

How do you rate this implementation? If you think it sucks, help me to improve it or suggest a better alternative.

推荐答案

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

I think you have a certain lack for separation of concerns with this model. I generally try to keep presentation to the Shell. See this question for how I wold implement this. It simplifies things and abstracts the idea of a RegionManager away from the Modules:

http://stackoverflow.com/questions/1671526/integrating-modules-with-application-in-prism-aka-compositewpf/1676837#1676837

这篇关于什么是从棱镜导航控件动态加载次数的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆