Wpf 选择TabItem时,从TabItem标题中删除下划线

Wpf 选择TabItem时,从TabItem标题中删除下划线,wpf,xaml,styles,Wpf,Xaml,Styles,当鼠标悬停在标题上时,我想在TabItem标题下加下划线,并在选中后删除下划线。 我尝试了以下代码: <Style x:Key="N3EntityNavigationItemStyle" TargetType="{x:Type Custom11:TabItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate Targe

当鼠标悬停在标题上时,我想在TabItem标题下加下划线,并在选中后删除下划线。 我尝试了以下代码:

    <Style x:Key="N3EntityNavigationItemStyle"  TargetType="{x:Type Custom11:TabItem}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type TabItem}">
                <Grid>
                    <Border Name="Border" BorderThickness="0,0,1,0" BorderBrush="White" Padding="5,2">
                        <ContentPresenter x:Name="CP" ContentSource="Header">
                        </ContentPresenter>
                    </Border>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsSelected" Value="true">
                        <Setter Property="TextElement.Foreground" TargetName="CP" Value="Black"/>
                        <Setter TargetName="Border" Property="Background" Value="White" />
                        <Setter Property="HeaderTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <TextBlock Text="{Binding}"></TextBlock>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsSelected" Value="False">
                        <Setter Property="Foreground" Value="White" />

                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="True">

                        <Setter Property="HeaderTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <TextBlock  Text="{Binding}"  TextDecorations="Underline"></TextBlock>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Trigger>

                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>


但是,在选择选项卡后,tabitem标题仍然保持下划线。

您是如何使用此xaml代码声明和分配
Style
元素的?请尝试将ismouseover触发器上移到触发器集合的顶部。