TabItem样式影响GroupBox样式

时间:2015-10-24 23:07:53

标签: c# wpf xaml tabcontrol tabitem

我有一个TabItem样式,可以在选中时更改TabItem的字体颜色。问题是这也改变了TabItem.Content中包含的GroupBox头的字体颜色,我无法做到这一点。这是代码:

风格

<Style x:Key="TabItem" TargetType="TabItem">
    <Setter Property="Padding" Value="10,7,2,7" />
    <Setter Property="BorderThickness" Value="0" />
    <Setter Property="Foreground"  Value="#333"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabItem}">
                <Border Padding="{TemplateBinding Padding}"  Name="tab" BorderThickness="0" BorderBrush="Transparent" SnapsToDevicePixels="True">
                    <ContentPresenter Name="content" ContentSource="Header" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter TargetName="tab" Property="Background" Value="#007ACC"/>
                        <Setter TargetName="tab" Property="BorderBrush" Value="#007ACC" />
                        <Setter TargetName="tab" Property="Cursor" Value="Arrow" />
                    </Trigger>
                    <Trigger Property="IsSelected" Value="False">
                        <Setter TargetName="tab" Property="Background" Value="#F0F0F0" />
                        <Setter TargetName="tab" Property="BorderBrush" Value="#F0F0F0" />
                        <Setter TargetName="tab" Property="Cursor" Value="Hand" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Foreground" Value="White"></Setter>
        </Trigger>
    </Style.Triggers>
</Style>

控制

<TabControl x:Name="tabControl1" Background="#FFF" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="-10,10,0,0" ScrollViewer.VerticalScrollBarVisibility="Visible" TabStripPlacement="Left">
    <TabItem Header="General" Style="{StaticResource TabItem}">
        <GroupBox Header="The text that shouldn't be (but is) turning white">
        </GroupBox>
    </TabItem>
</TabControl>

GroupBox是基于TabItem还是包含一个?

1 个答案:

答案 0 :(得分:0)

它是关于逻辑和可视树的属性继承。 这将解释further