我面临标签控件绑定到视图模型集合的问题,类似于这篇文章
<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>
但正如上面文章中提到的,我看到视图模型被构建了两次。当我尝试填充可观察选项卡集合时,首先在 MainViewModel 中,当我尝试导航到 tabitem 时。
我怎样才能避免这种情况?