I have this WPF 4 code:
<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>
<EventTr开发者_开发问答igger 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>
Problem is that default button animation is still present. I don't want use OverridesDefaultStyle parameter. Is possible clear storyboard somehow?
Try do your animations with EnterActions and ExitActions on IsMouseOver Property Instead of the events.
精彩评论