【问题标题】:Prism Modules having its own Regions in View棱镜模块在视图中有自己的区域
【发布时间】:2012-09-25 16:03:18
【问题描述】:

我正在使用 Silverlight 5 (MefBootstrapper) 在 Prism V4.1 中练习。不幸的是,我找不到这样的情况的实现:

  1. 我的 Shell.xaml 中有 2 个区域。
  2. 我的模块(modulescatalog.xaml 中描述的 xap 文件)(Module1 和 Module2)被注入到这个区域;
  3. 我在模块(例如模块 1)中的一个视图有它自己的区域。

我想使用 prism 框架的强大功能将另一个模块注入到此 Module1 视图中。事实上,这个模块应该是一个小棱镜应用程序,它有自己的模块,应该有可能将参数传递给 Module2 和其他模块。

有什么方法可以实现吗?

我的意思是:View可以在Module1里面创建自己的Region,那么依赖的模块就可以把view注入到这个Region吗?

【问题讨论】:

    标签: c# silverlight prism-4


    【解决方案1】:

    是的,它可以,为什么不呢?加载依赖模块后,只需在该区域注册视图即可。例如,您可以在依赖模块的IModule.Initialize 方法中执行此操作:

    public void Initialize()
    {
        regionManager.RegisterViewWithRegion("Module1RegionName", () => serviceLocator.GetInstance<DependentModuleView>());
    }
    

    然后您可以导航到该视图或在注册后立即激活它。

    regionManager.RequestNavigate("Module1RegionName", new Uri("DependentModuleView", UriKind.Relative));
    
    //or resolve the view and activate it
    var view = serviceLocator.GetInstance<DependentModuleView>();
    var region = regionManager.Regions["Module1RegionName"];
    region.Activate(view);
    

    至于模块之间的通信,您有几个选择。阅读Communicating Between Loosely Coupled Components了解更多信息。

    【讨论】:

    • ,谢谢您的帮助。但是当我尝试解决视图时出现错误。 IModule.Initialize 中的此代码引发异常:ServiceLocator.Current.GetInstance&lt;LoaderTabView&gt;(); 异常:尝试获取 LoaderTabView 类型的实例时发生激活错误,键“”视图类:[Export("LoaderTabView")] public partial class LoaderTabView : UserControl
    • 我发现了我的错误。我应该使用[Export] public partial class LoaderTabView : UserControl 而不是[Export("LoaderTabView")] public partial class LoaderTabView : UserControl
    • @Grigory 很高兴你知道这一点。
    猜你喜欢
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多