MEF + DirectoryCatalog +按需
我在ModuleB中有一个代码Initialize():
this.regionManager.AddToRegion("TabRegion", new Views.Container());
this.regionManager.AddToRegion("TabRegion", new Views.Container());
并单击Shell上的事件:
modulemanager.LoadModule("ModuleB");
因此我在shell tabcontrol中看到了2个标签
对我来说问题是再次打电话:
this.regionManager.AddToRegion("TabRegion", new Views.Container());
怎么做? 非常感谢
PS 我试图在网上找到解决方案,但我想我的问题不合适。
答案 0 :(得分:0)
如果此代码仅从ModuleB构造函数(或某些嵌套方法)中调用 ,则唯一的方法是创建另一个ModuleB实例。以下文章可以为您提供帮助:Dynamic Part Instantiation in MEF。
但是,如果你可以将该方法设为静态,那么你可以在以后将其称为多次,如你所需。
答案 1 :(得分:0)
使用EventAggregator:
将构造函数导入Shell初始化
public Shell(IEventAggregator _eventaggregator);
在运行时调用
eventaggregator.GetEvent().Publish("STOCK0");
在模块的Initialize()中订阅事件
eventaggregator.GetEvent().Subscribe(CreateView);
只需创建Action CreateView并在其中调用add2region:
this.regionManager.AddToRegion("TabRegion", new Views.Container());
链接到同一问题和答案Loading a prism module view from the shell, using MEF