.NET WPF 抖动动画

.NET WPF 抖动动画

Demo



Code

xml 复制代码
<!-- 水平抖动 -->
<Button Content="Hello World">
    <Button.RenderTransform>
        <TranslateTransform x:Name="translateTransform" />
    </Button.RenderTransform>
    <Button.Triggers>
        <EventTrigger RoutedEvent="Button.MouseEnter">
            <BeginStoryboard>
                <BeginStoryboard.Storyboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetName="translateTransform"
                            Storyboard.TargetProperty="X"
                            To="2"
                            Duration="0:0:0.075" />
                        <DoubleAnimation
                            BeginTime="0:0:0.075"
                            Storyboard.TargetName="translateTransform"
                            Storyboard.TargetProperty="X"
                            To="-2"
                            Duration="0:0:0.15" />
                        <DoubleAnimation
                            BeginTime="0:0:0.225"
                            Storyboard.TargetName="translateTransform"
                            Storyboard.TargetProperty="X"
                            To="0"
                            Duration="0:0:0.075" />
                    </Storyboard>
                </BeginStoryboard.Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Button.Triggers>
</Button>
<!-- 竖直抖动 -->
<Button Content="Hello World">
    <Button.RenderTransform>
        <TranslateTransform x:Name="translateTransform1" />
    </Button.RenderTransform>
    <Button.Triggers>
        <EventTrigger RoutedEvent="Button.MouseEnter">
            <BeginStoryboard>
                <BeginStoryboard.Storyboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetName="translateTransform1"
                            Storyboard.TargetProperty="Y"
                            To="2"
                            Duration="0:0:0.075" />
                        <DoubleAnimation
                            BeginTime="0:0:0.075"
                            Storyboard.TargetName="translateTransform1"
                            Storyboard.TargetProperty="Y"
                            To="-2"
                            Duration="0:0:0.15" />
                        <DoubleAnimation
                            BeginTime="0:0:0.225"
                            Storyboard.TargetName="translateTransform1"
                            Storyboard.TargetProperty="Y"
                            To="0"
                            Duration="0:0:0.075" />
                    </Storyboard>
                </BeginStoryboard.Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Button.Triggers>
</Button>
<!-- 旋转抖动 -->
<Button Content="Hello World">
    <Button.RenderTransform>
        <RotateTransform x:Name="rotateTransform" />
    </Button.RenderTransform>
    <Button.RenderTransformOrigin>
        <Point X="0.5" Y="0.5" />
    </Button.RenderTransformOrigin>
    <Button.Triggers>
        <EventTrigger RoutedEvent="Button.MouseEnter">
            <BeginStoryboard>
                <BeginStoryboard.Storyboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetName="rotateTransform"
                            Storyboard.TargetProperty="Angle"
                            To="5"
                            Duration="0:0:0.075" />
                        <DoubleAnimation
                            BeginTime="0:0:0.075"
                            Storyboard.TargetName="rotateTransform"
                            Storyboard.TargetProperty="Angle"
                            To="-5"
                            Duration="0:0:0.15" />
                        <DoubleAnimation
                            BeginTime="0:0:0.225"
                            Storyboard.TargetName="rotateTransform"
                            Storyboard.TargetProperty="Angle"
                            To="0"
                            Duration="0:0:0.075" />
                    </Storyboard>
                </BeginStoryboard.Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Button.Triggers>
</Button>
相关推荐
九鼎科技-Leo3 小时前
了解 .NET 运行时与 .NET 框架:基础概念与相互关系
windows·c#·.net
九鼎科技-Leo5 小时前
什么是 ASP.NET Core?与 ASP.NET MVC 有什么区别?
windows·后端·c#·asp.net·mvc·.net
.net开发5 小时前
WPF怎么通过RestSharp向后端发请求
前端·c#·.net·wpf
九鼎科技-Leo6 小时前
WPF 中 NavigationWindow 与 Page 的继承关系解析
wpf
SongYuLong的博客6 小时前
C# WPF 打印机
wpf
就是有点傻6 小时前
WPF中的转换器
wpf
九鼎科技-Leo10 小时前
在 C# 中,ICollection 和 IList 接口有什么区别?
windows·c#·.net
时光追逐者10 小时前
C#/.NET/.NET Core学习路线集合,学习不迷路!
开发语言·学习·c#·asp.net·.net·.netcore·微软技术
Crazy Struggle13 小时前
.NET 全功能流媒体管理控制接口平台
.net·开源项目·流媒体
.net开发13 小时前
WPF使用prism框架发布订阅实现消息提示
c#·.net·wpf