I have a WPF xaml TabControl defined as below, how to set Visibility to Collapsed for the tab item based on binding? Current code:
<TabControl>
<DataTemplate DataType="{x:Type foo:FooViewModel}">
<foo:FooView/>
</DataTemplate>
<DataTemplate DataType="{x:Type bar:BarViewModel}">
<bar:BarView/>
</DataTemplate>
<TabControl/>
What I want to implement to only hide foo TabItem based on condition, but seems it cannot specify the target name?? E.g. hide the template which name is Foo. Thanks for your help, have a nice day.
<TabControl ItemsSource="{Binding ParentModel}">
<DataTemplate x:Name="Foo" DataType="{x:Type foo:FooViewModel}">
<foo:FooView/>
</DataTemplate>
<DataTemplate x:Name="Bar" DataType="{x:Type bar:BarViewModel}">
<bar:BarView/>
</DataTemplate>
<TabControl.ItemContinerStyle>
<Style TargetType="TabItem" 'e.g. TargetName="Foo"<==========='>
<Style.Triggers>
...Some trigger condition ignored here
<Setter Property="Visibility" Value="Collapsed" />
</Style.Triggers>
</Style>
<TabControl.ItemContinerStyle/>
<TabControl/>