如何在WPF按钮中禁用动画

时间:2010-10-18 09:10:20

标签: wpf

我有这个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 参数。有可能以某种方式清晰的故事板吗?

1 个答案:

答案 0 :(得分:2)

尝试使用IsMouseOver属性上的EnterActions和ExitActions而不是事件来制作动画。