简体   繁体   中英

setting the TabItem IsSelected background

I can't seem to control the background color of the selected tab. I can use the IsSelected trigger to control the value of the non-selected tabs however.

This code:

<Style TargetType="{x:Type TabItem}">
    <Setter Property="Background" Value="Black" />
    <Setter Property="Foreground" Value="#EE444444" />
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="false">
             <Setter Property="Background" Value="Pink"/>
        </Trigger>
    </Style.Triggers>
</Style>

works, in setting the un-selected tabs background to pink. However, the selected tabs following some light gray color I can't get rid of.

I also tried this:

<Style TargetType="{x:Type TabItem}">
    <Setter Property="Background" Value="Black" />
    <Setter Property="Foreground" Value="#EE444444" />
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="false">
            <Setter Property="Background" Value="Pink"/>
        </Trigger>
        <Trigger Property="IsSelected" Value="true">
            <Setter Property="Background" Value="Red"/>
        </Trigger>
    </Style.Triggers>
</Style>

but none of these have any affect on selected tab. The only thing I can think of is that some referenced assembly has a generic tab style?

This style is located in the same file as the tab control, in the Grid.Resources section.

the TabItem selection behaviour is defined at the Template level. If you want to change the color, define a whole new DataTemplate, and define triggers in that template to change color. Then define that template as the ItemTemplate of your TabControl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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