【发布时间】:2011-12-20 09:35:47
【问题描述】:
我有一个 shell 项目,它将引导程序中的模块加载到我的 shell 主视图中的选项卡控件中。
我刚刚在我的标签项上实现了一个关闭按钮,现在提出了如何从 shell 重新加载模块视图的问题?
尝试使用
moduleManager.LoadModule("ModuleA");
但这仅在模块首次加载时有效。当我调用上面的内容时,它会加载并初始化模块,显示视图。如果我再次关闭视图,我第二次尝试这个时它不会重新显示视图(我猜它不会重新初始化模块,因为它已经加载了)。
所以,我虽然想过在我的 shell 中使用以下内容:
var moduleAView = ServiceLocator.Current.GetInstance<ModuleAView>();
regionManager.Regions["TabRegion"].Add(ModuleAView);
regionManager.Regions["TabRegion"].Activate(ModuleAView);
这种方法的问题是我的 shell 如何知道第 1 行中的 ModuleAView 类型?我没有对模块 A 的引用,也不想添加一个。我考虑了 ModuleAView 将实现的通用接口,它可以在模块和外壳之间共享,但是在尝试使用上面的 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));
}
}
【问题讨论】: