1
我有一個TabItem風格,可以在選擇TabItem時改變它的字體顏色。問題是這也改變了包含在TabItem.Content中的GroupBox標題的字體顏色,我不能這樣做。下面的代碼:影響GroupBox風格的TabItem風格
風格
<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>
是立足於TabItem的組框或者它包含一個?
您是否曾經解決過這個問題? –
不,我沒有。 –