2011-12-20 57 views
3

從shell中加載棱鏡模塊視圖我有一個shell項目,它將我的引導程序中的模塊加載到我的shell主視圖中的選項卡控件中。使用MEF

我剛剛在我的選項卡上實現了一個關閉按鈕,現在提出瞭如何從shell重新加載模塊視圖的問題?

使用

moduleManager.LoadModule("ModuleA"); 

嘗試,但在第一次加載這隻能模塊。當我調用上面的代碼時,它會加載並初始化模塊,顯示視圖。如果我再次關閉視圖,第二次我嘗試這個它不會重新顯示視圖(我猜它沒有重新初始化模塊,因爲它已經加載)。

所以,我雖然我想過使用的東西沿着我的外殼下面的幾行:

var moduleAView = ServiceLocator.Current.GetInstance<ModuleAView>(); 
regionManager.Regions["TabRegion"].Add(ModuleAView); 
regionManager.Regions["TabRegion"].Activate(ModuleAView); 

麻煩這種方法是如何我不知道貝約在第1行的類型ModuleAView?我沒有對模塊A的引用,也不想添加一個。我想過一個ModuleAView將實現的通用接口,它可以在模塊和shell之間共享,但是當嘗試使用上述的ServiceLocator.GetInstance方法時,出現了組合錯誤。

非常感謝您的幫助。

PS 這是我試過的模塊A模塊代碼。

[ModuleExport(typeof(ModuleA), InitializationMode = InitializationMode.OnDemand)] 
[Module(ModuleName="ModuleA")] 
public class ModuleA : IModule 
{ 
    private IRegionManager _regionManager; 

    [ImportingConstructor] 
    public ModuleA(IRegionManager regionManager) 
    { 
     this._regionManager = regionManager; 
    } 

    public void Initialize() 
    { 
     // add the search view to the region manager. 
     this._regionManager.RegisterViewWithRegion("TabRegion", typeof(Views.ModuleAView)); 
    } 
} 

回答

1

可能是錯誤的思路。

而不是嘗試從shell顯示模塊的視圖,我從moduleA模塊訂閱的shell發佈一個事件。然後,我可以決定在模塊本身顯示的視圖。

希望這會有所幫助。