I created a TabControl whose Header's contents are two TextBlocks: one labeling the Header with a name, the other showing a symbol font. Depending on the selected TabItem I want to show the Header text in the first TextBlock, while collapsing it, as soon as another TabItem is selected (therefore showing the Header text of the now selected TabItem).
E.g.: Selecting TabItem1 shows TextBlock1 with the Header text, TextBlock2 is showing a symbol font. Selecting TabItem2 collapses the TextBlock1 Visibility, and therefore sets the first TextBlock's Visibility of TabItem2 form Collapsed to Visible.
I would like to try a xaml-solution; with code behind I can achieve the desired functionality. I guess I would need some trigger, but I am obviously too unexperienced with xaml to implement them properly.
Here is what I got so far. Please note that my code does show the expected behaviour for the first time, but then Visibility of the TextBlock is always set to "collapsed". Here's my code:
<TabItem x:Name="Item2" GotFocus="Item2_GotFocus" LostFocus="Item2_LostFocus">
<TabItem.Header>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="Text2" FontSize="14" FontFamily="Quicksand" VerticalAlignment="Center" Content="TestEntry">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=Item2, Path=IsFocused}" Value="True">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
<TextBlock Margin="20,0,0,0" FontSize="32" FontFamily="APPFONT" VerticalAlignment="Center">B</TextBlock>
</StackPanel>
</TabItem.Header>
</TabItem>
By starting the app I get to see both TextBlocks; as soon as another TabItem is chosen, the first TextBlock's visibility is set to collapsed. Clicking again on this TabItem shows the first TextBlock not again.
IsSelected
instead ofIsFocused
?