开发者

How to disable animation in WPF button

开发者 https://www.devze.com 2023-01-20 18:25 出处:网络
I have this WPF 4 code: <Button Content=\"{Binding Path=Header}\" Command=\"{Binding Path=Command}\" CommandParameter=\"{Binding Path=CommandParameter}\" Focusable=\"False\">

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消