I have been attempting to create a TabControl with TabItems (tabs) that have a background image that changes when selected. I also would like the background of the TabItem to be transparent.
I have tried many different things. I managed to get the transparent background on the TabItem working with this:
And the changing image working with this:
But I couldn't seem to combine the two no matter what I tried.
I finally managed to get a transparent background on a TabItem that changes image on isSelected using this :
Set Image When TabItem isSelected
combined with the Styling TabItems link but in testing it for one tab it is causing the second TabItem to have the same background image as the first tab, although the behaviour is exactly what I want, they are changing when selected.
I am thinking it has something to do with the way I have the Stackpanel inside the Grid, but I'm not sure.
Thanks!
This is the code that I have currently:
<TabControl TabStripPlacement="Left" Height="500" Width="700" Margin="0,0,200,0">
<TabControl.Resources>
<Style TargetType="TabItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabItem">
<Grid Name="Panel">
<ContentPresenter x:Name="ContentSite" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header" Margin="10,2"/>
<StackPanel>
<HeaderedItemsControl>
<Image x:Name="imgUsers" Source="/images/usersBtnPressed.png" Height="75"/>
</HeaderedItemsControl>
</StackPanel>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Panel" Property="Background" Value="Transparent"/>
<Setter TargetName="imgUsers" Property="Source" Value="/images/usersBtnPressed.png"/>
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="imgUsers" Property="Source" Value="/images/usersBtn.png"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</TabControl.Resources>
<TabItem Name="tabUsers">
<TabItem.HeaderTemplate>
<DataTemplate>
<StackPanel>
</StackPanel>
</DataTemplate>
</TabItem.HeaderTemplate>
</TabItem>
<TabItem>
<TabItem.HeaderTemplate>
<DataTemplate>
<StackPanel>
<Image Source="/images/membersBtn.png" Height="75" Width="150"/>
</StackPanel>
</DataTemplate>
</TabItem.HeaderTemplate>
</TabItem>
</TabControl>