Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Shell中向Tabcontrol添加视图的新副本?_C#_Wpf_Prism_Tabcontrol - Fatal编程技术网

C# 如何在Shell中向Tabcontrol添加视图的新副本?

C# 如何在Shell中向Tabcontrol添加视图的新副本?,c#,wpf,prism,tabcontrol,C#,Wpf,Prism,Tabcontrol,MEF+目录目录+OnDemand 我在ModuleB中有一个代码Initialize(): this.regionManager.AddToRegion("TabRegion", new Views.Container()); this.regionManager.AddToRegion("TabRegion", new Views.Container()); 然后单击Shell上的事件: modulemanager.LoadModule("ModuleB"); 因此,我在shell ta

MEF+目录目录+OnDemand

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

this.regionManager.AddToRegion("TabRegion", new Views.Container());
this.regionManager.AddToRegion("TabRegion", new Views.Container());
然后单击Shell上的事件:

modulemanager.LoadModule("ModuleB");
因此,我在shell tabcontrol中看到了两个选项卡

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

this.regionManager.AddToRegion("TabRegion", new Views.Container());
怎么做? 非常感谢

PS
我试图在web上找到解决方案,但我想我的问题是不正确的。

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


但是如果您可以将该方法设置为静态,那么您可以根据需要随时调用它。

使用EventAggregator:

  • 使用创建基础架构项目 PublishModuleAgainer:CompositePresentationEvent类
  • 将构造函数导入Shell初始化的点

    public Shell(IEventAggregator _eventaggregator);
    
  • 运行时调用

    eventaggregator.GetEvent().Publish("STOCK0");
    
  • 在模块subscribe to event的Initialize()中

    eventaggregator.GetEvent().Subscribe(CreateView);
    
  • 只需创建Action CreateView并在其中调用add2region:

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

  • 链接到同一个问题和答案

    如果你对你的解决方案做出一个答案,然后将其标记为答案(点击空心复选标记)会更好。这对我来说是个惊喜,有人编辑了我的帖子!谢谢,顺便说一下,我将编辑一些代码样式。stackoverflow设置为有好的、社区维护的问题和答案,因此任何人都可以编辑任何帖子(尽管如果他们编辑得不好,其他人会撤销)。请不要删除答案中的链接!