C#WPF-如何修改ToolBar.ButtonStyleKey样式

C#WPF-如何修改ToolBar.ButtonStyleKey样式,c#,wpf,styles,C#,Wpf,Styles,我需要在鼠标悬停时显示工具栏按钮边框,否则将其隐藏。我试着做到以下几点: <Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="Button" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"> <Setter Property="Foreground" Value="Blue"/> <Setter Proper

我需要在鼠标悬停时显示工具栏按钮边框,否则将其隐藏。我试着做到以下几点:

<Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="Button" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}">
    <Setter Property="Foreground" Value="Blue"/>
    <Setter Property="Control.Background" Value="Transparent" />
    <Setter Property="Control.BorderBrush" Value="Transparent" />
    <Setter Property="Control.BorderThickness" Value="1" />
    <Setter Property="HorizontalAlignment" Value="Center"/>
    <Setter Property="VerticalAlignment" Value="Center"/>

    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="Control.BorderBrush"  Value="Red"/>
        </Trigger>
    </Style.Triggers>
</Style>

但它并没有像预期的那样起作用。我期望发生的是,鼠标上的边框将变成红色,否则将是透明的。实际结果是,它的行为类似于默认行为中的默认颜色。
我肯定做错了什么事。

有人知道它是什么吗?

在工具栏中使用时,请尝试以下操作以覆盖由ToolBar.ButtonStyleKey标识的按钮样式

<ToolBar.Resources>
    <Style x:Key="{x:Static ToolBar.ButtonStyleKey}" TargetType="{x:Type Button}">
        <Setter Property="Foreground"
           Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="Padding" Value="2"/>
        <Setter Property="BorderThickness" Value="4"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template">
           <Setter.Value>
             <ControlTemplate TargetType="{x:Type Button}">
                 <Border x:Name="Bd"
                    SnapsToDevicePixels="true"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Padding="{TemplateBinding Padding}">
                      <ContentPresenter
                         HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                         VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                  </Border>
                  <ControlTemplate.Triggers>
                     <Trigger Property="IsMouseOver" Value="true">
                       <Setter Property="BorderBrush" TargetName="Bd" Value="Orange"/>
                     </Trigger>
                  </ControlTemplate.Triggers>
             </ControlTemplate>
           </Setter.Value>
        </Setter>
    </Style>
</ToolBar.Resources>