0

MEF+目录目录+按需

我在 ModuleB 中有一个代码 Initialize():

this.regionManager.AddToRegion("TabRegion", new Views.Container());
this.regionManager.AddToRegion("TabRegion", new Views.Container());

并单击外壳上的事件:

modulemanager.LoadModule("ModuleB");

结果,我在 shell tabcontrol 中看到了 2 个选项卡

对我来说,问题是再次打电话:

this.regionManager.AddToRegion("TabRegion", new Views.Container());

怎么做?非常感谢

PS我试图在网上找到解决方案,但我想我的问题不合适。

4

2 回答 2

0

Using the EventAggregator:

  1. Create Infrastucture project with PublishModuleAgainer:CompositePresentationEvent class
  2. Point Importing constructor to Shell initializing

    public Shell(IEventAggregator _eventaggregator);
    
  3. Call in runtime

    eventaggregator.GetEvent().Publish("STOCK0");
    
  4. In Initialize() of module subscribe to event

    eventaggregator.GetEvent().Subscribe(CreateView);
    
  5. Just create Action CreateView and call add2region inside it:

    this.regionManager.AddToRegion("TabRegion", new Views.Container());
    

Link to the same question and an answer Loading a prism module view from the shell, using MEF

于 2012-08-09T14:48:41.043 回答
0

如果仅从ModuleB 构造函数(或某些嵌套方法)调用此代码,那么您唯一的方法是创建 ModuleB 的另一个实例。这是可能对您有所帮助的文章:MEF 中的动态部件实例化

但是,如果您可以将该方法设为静态,那么您可以在以后根据需要多次调用它。

于 2012-08-06T10:07:16.123 回答