简体   繁体   English

使用datatemplate将viewmodel的集合绑定到tabcontrol

[英]Binding collection of viewmodel to tabcontrol with datatemplate

I am facing problem with tab control binding to collection of view models similar as in this post 我在将标签控件绑定到类似于本文的视图模型的集合时遇到了问题

<Window.Resources>
  <ViewModel:MainViewModel x:Key="MainViewModel" />
  <DataTemplate DataType="{x:Type local:Foo1}">
    <local:UserControl1 />
  </DataTemplate>
  <DataTemplate DataType="{x:Type local:Foo2}">
    <local:UserControl2 />
  </DataTemplate>
  <DataTemplate DataType="{x:Type local:Foo3}">
    <local:UserControl3 />
  </DataTemplate>
</Window.Resources>
<igDock:XamDockManager x:Name="dm">
  <igDock:XamDockManager.Panes>
    <igDock:SplitPane>
      <igDock:ContentPane>
        <ContentControl>
          <local:Foo />
        </ContentControl>
      </igDock:ContentPane>
    </igDock:SplitPane>
  </igDock:XamDockManager.Panes>
</igDock:XamDockManager>
<DockPanel>
  <igDock:XamDockManager x:Name="dockManager">
    <igDock:TabGroupPane DataContext="{StaticResource ResourceKey=MainViewModel}"
                         SelectedIndex="{Binding SelectedTabIndex}">
      <igExtensions:ContentPaneFactory.PaneFactory>
        <igExtensions:ContentPaneFactory ItemsSource="{Binding TabCollection}"
                                         HeaderPath="Title"
                                         ContentPath="." />
      </igExtensions:ContentPaneFactory.PaneFactory>
    </igDock:TabGroupPane>
  </igDock:XamDockManager>
</DockPanel>

But as mentioned in the above article, i see that the viewmodel are getting constructed twice. 但是正如上面的文章中提到的,我看到viewmodel被构造了两次。 First in MainViewModel when I try to populate the observable tab collection and once when I try to navigate to the tabitem. 当我尝试填充可观察的选项卡集合时,首先是在MainViewModel中,而当我尝试导航到Tabitem时,第一次。

How can I avoid this?. 如何避免这种情况?

I believe that this question is already answered in the Infragistics's forum thread that you have linked. 我相信这个问题已经在您链接的Infragistics的论坛主题中得到解答。

If you have further questions I can suggest you ask them in the IG forums, since you can get an answer from an IG expert. 如果您还有其他问题,我建议您在IG论坛中提问,因为您可以从IG专家那里得到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM