我有一个这样定义的按钮样式:
<LinearGradientBrush x:Key="Brush_NavButtonBorder0" StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#00383f47" Offset="0" />
<GradientStop Color="#FF383f47" Offset="1" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="Brush_NavButtonBorder4" StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#FF414f5a" Offset="0" />
<GradientStop Color="#11414f5a" Offset="1" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="Brush_NavButtonBackground" StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#FF3f505a" Offset="0" />
<GradientStop Color="#FF37454e" Offset="0.75" />
<GradientStop Color="#FF2f3c44" Offset="1" />
</LinearGradientBrush>
<LinearGradientBrush x:Key="Brush_NavButtonPressedBackground" StartPoint="0,0" EndPoint="0,1" >
<GradientStop Color="#FF3f505a" Offset="1" />
<GradientStop Color="#FF37454e" Offset="0.25" />
<GradientStop Color="#FF2f3c44" Offset="0" />
</LinearGradientBrush>
<Style x:Key="NavigationButton" TargetType="Button">
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="Foreground" Value="Gainsboro" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Background" Value="{StaticResource Brush_NavButtonBackground}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}" x:Name="MainControlTemplate">
<Grid>
<Border x:Name="outerBorder" CornerRadius="5" BorderThickness="1" BorderBrush="{StaticResource Brush_NavButtonBorder0}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True" />
<Border Margin="1" CornerRadius="4" BorderThickness="1" BorderBrush="{StaticResource Brush_NavButtonBorder4}" Background="Transparent" SnapsToDevicePixels="True">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Name="content"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<!--<Setter TargetName="outerBorder" Property="BorderBrush" Value="Gray" />-->
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="outerBorder"
Storyboard.TargetProperty="(Border.BorderBrush).(GradientBrush.GradientStops)[0].(GradientStop.Color)"
To="Gray"
Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{StaticResource Brush_NavButtonPressedBackground}" />
<Setter TargetName="content" Property="RenderTransform" >
<Setter.Value>
<TranslateTransform X="2.0" Y="2.0" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter Property="FocusVisualStyle" Value="{StaticResource MyFocusVisualStyle}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这种风格有几个问题: 1. 当我将鼠标悬停在一个按钮上时,所有其他使用这种风格的按钮都会对动画做出反应,而不仅仅是我结束的按钮。2. 我想为整个边框的颜色设置动画,而不仅仅是第 0 个渐变停止点,但我似乎找不到这样做的方法。
ColorAnimation 部分上方的注释行几乎完全符合我的要求,只是它立即在 MouseOver 上显示灰色 BorderBrush - 我希望它显示带有动画的灰色 BorderBrush。
这似乎应该很简单,但我不知道如何做到这一点。有谁知道如何以正确的方式做到这一点?