2011-11-29 306 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*/)); 
相關問題