0
votes

I am re-styling a TabItem and want the background, foreground, and text color of the TabItem Header to be different depending on selected or not. I can successfully change the TextBlock of the ContentPresenter outside the ControlTemplate.Triggers, but I'm not sure how to "get to" it from within the Trigger.

Here is my 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>
1
I don't understand your question. You want to change which property of which element? - Federico Berasategui
Okay to simplified the question: in the "IsSelected" trigger, I want the text of the Header (i.e. ContentPresenter) to be black instead of LightGray. - Jake Shakesworth

1 Answers

0
votes

In your second Trigger set property IsSelected instead of IsEnabled it will work fine. I hope this will help.