2011-11-29 304 views
2

我正在使用Prism,MEF(MEF Bootstrapper)和WPF。我是这些新手,我有一个非常简单的应用程序,我试图去工作。RegionManager不包含我配置的区域

我有两个区域在主窗口(外壳)哪些工作很好。我可以在运行时在窗口中看到它们,我可以从Shell窗口中的代码和其他窗口中通过TheRegionManager.Regions [“regionName”]访问它们。为此,我使用: [导入] public IRegionManager TheRegionManager {private get;设置;}

现在我想为应用程序中的另一个窗口做同样的事情。我在这两个地区,我从XAML配置他们,我做的事:

 TheRegionManager.RegisterViewWithRegion("AdsMainRegion", typeof(Ads)); 
     TheRegionManager.RegisterViewWithRegion("AdDetailsRegion", typeof(AdsDetail)); 

为了从壳牌等2个地区注册类似的看法。这种工作是因为我可以在运行时看到在区域中加载的视图。问题是我无法从代码中访问的国家和地区: 进口TheRegionManager是空的,我所要做的

  TheRegionManager = ServiceLocator.Current.GetInstance<IRegionManager>(); wich returns a region manager that contain only the 2 regions from the Shell window but not the 2 regions from this other window that I want. 

     I'm sure that I'm missing something. Maybe I need to add some code to the bootstrapper. Or I should add this other window as a module in the catalog? Why does it work fine in Shell window and not in this other window? 
+2

我最终解决了我的问题。在获得带有服务定位器的RegionManager后,我必须执行RegionManager.SetRegionManager(view,..)以将区域管理器设置为视图。 –

+0

解决了吗?如果是这样,请回答或关闭您的问题。 – PVitt

回答

0

转到你的窗口的代码隐藏和:

protected override void OnInitialized(System.EventArgs e) 
    { 
     base.OnInitialized(e); 

     var regionManager = ServiceLocator.Current.GetService(typeof(IRegionManager)) as IRegionManager; 
     RegionManager.SetRegionManager(/*content control for region manager*/, regionManager); 
    } 
现在

在您的视图模式:

TheRegionManager.RegisterViewWithRegion(/*region name*/, typeof(/*view type*/)); 
相关问题