0
我正在重新設計一個TabItem,並且希望TabItem標題的背景,前景和文本顏色根據選擇與否而不同。我可以成功地更改ControlTemplate.Triggers之外的ContentPresenter的TextBlock,但我不確定如何從觸發器中「獲取」它。如何設置觸發器內的TabItem ContentPresenter的樣式?
這是我的XAML:
<Style x:Key="SiteTabItemStyle" d:IsControlPart="True" TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Border Margin="0,0,-4,0" x:Name="Border" BorderThickness="2" CornerRadius="15,15,0,0" BorderBrush="Black" Background="DimGray">
<ContentPresenter TextBlock.Foreground="LightGray" HorizontalAlignment="Center" Margin="12,2,12,2" x:Name="ContentSite" VerticalAlignment="Center" RecognizesAccessKey="True" ContentSource="Header"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Panel.ZIndex" Value="100"/>
<Setter Property="Background" Value="Gold" TargetName="Border"/>
<Setter Property="BorderThickness" Value="2" TargetName="Border"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" Value="{DynamicResource DisabledBackgroundBrush}" TargetName="Border"/>
<Setter Property="BorderBrush" Value="{DynamicResource DisabledBorderBrush}" TargetName="Border"/>
<Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我不明白你的問題。你想改變哪個元素的屬性? –
好的,簡化了這個問題:在「IsSelected」觸發器中,我希望Header(即ContentPresenter)的文本是黑色的,而不是LightGray。 –