我有这个WPF 4代码:
<Button Content="{Binding Path=Header}" Command="{Binding Path=Command}" CommandParameter="{Binding Path=CommandParameter}" Focusable="False">
<Button.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="Silver" Offset="1" x:Name="bgcolor" />
</LinearGradientBrush>
</Button.Background>
<Button.Triggers>
<EventTrigger RoutedEvent="Button.MouseEnter">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="bgcolor" Storyboard.TargetProperty="Color" To="Red" Duration="0:0:0"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Button.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="bgcolor" Storyboard.TargetProperty="Color" To="Silver" Duration="0:0:0"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
问题是默认按钮动画仍然存在。我不想使用 OverridesDefaultStyle 参数。有可能以某种方式清晰的故事板吗?
答案 0 :(得分:2)
尝试使用IsMouseOver属性上的EnterActions和ExitActions而不是事件来制作动画。