【问题标题】:How to create nested regions?如何创建嵌套区域?
【发布时间】:2012-03-02 21:23:36
【问题描述】:

我正在使用 PRISM 和 Unity Container。

我的 shell 中有一个 TabControl 和一个名为 MainRegion 的区域。

然后我在另一个名为 Common 的项目中有一个视图。这个视图包含一个ContentRegion 区域和它下面的两个按钮。

使用这个公共项目,我创建了几个引用公共项目的模块。当我创建一个新模块时,我需要在上一个项目的ContentRegion 中创建应该放置它的视图。

请查看下面的图片。

我的意思是我创建的每个模块,我需要为 ContentRegion 创建一个视图。

我不知道如何实现这种情况,你能指导我吗?

【问题讨论】:

    标签: c# wpf module prism region


    【解决方案1】:

    根据您的问题很难说出您想要做什么,但我会试一试。看起来您想要的是本地范围的区域管理器。

    因此,在每个模块中,您都会将公共视图添加到选项卡控制区域。它可能看起来像这样:

    public class ModuleA
    {
       public ModuleA(IRegionManager regionManager) 
       {
          _shellRegionManager = regionManager;
       }
       public bool Initialize()
       {
          IRegion tabRegion = _shellRegionManager.Regions["tabRegion"];
    
          //You may actually want to use your container to resolve the common view, but 
          //I'm creating it here for demonstration sake.
          Object commonView = new CommonView();
    
          //This is the important part... setting the 3rd parameter to true gives us 
          //a new locally scoped region manager, so Prism won't complain about the fact
          //that the common view contains regions with names that have already been 
          //registered in other modules
          IRegionManager localRM = tabRegion.Add(new CommonView, "ModuleACommon", true);
    
          IRegion commonContentRegion = localRM.Regions["ContentRegion"];
          commonContentRegion.Add(new ModuleAView()); 
    
       }
       IRegionManager _shellRegionManager;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-01
      • 1970-01-01
      • 2010-09-16
      • 2016-12-18
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 2011-02-01
      • 2018-11-28
      相关资源
      最近更新 更多