简体   繁体   English

设置TabItem IsSelected背景

[英]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. 我可以使用IsSelected触发器来控制未选择的选项卡的值。

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. 此样式与Grid.Resources部分中的选项卡控件位于同一文件中。

the TabItem selection behaviour is defined at the Template level. TabItem选择行为是在模板级别定义的。 If you want to change the color, define a whole new DataTemplate, and define triggers in that template to change color. 如果要更改颜色,请定义一个全新的DataTemplate,然后在该模板中定义触发器以更改颜色。 Then define that template as the ItemTemplate of your TabControl. 然后将该模板定义为TabControl的ItemTemplate。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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