.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>
相关推荐
步、步、为营2 小时前
解锁.NET配置魔法:打造强大的配置体系结构
数据库·oracle·.net
踏上青云路7 小时前
xceed PropertyGrid 如何做成Visual Studio 的属性窗口样子
ide·wpf·visual studio
code_shenbing8 小时前
基于 WPF 平台使用纯 C# 实现动态处理 json 字符串
c#·json·wpf
鱼是一只鱼啊12 小时前
.netframeworke4.6.2升级.net8问题处理
开发语言·.net·.net8
苏克贝塔13 小时前
WPF5-x名称空间
wpf
xcLeigh16 小时前
WPF实战案例 | C# WPF实现大学选课系统
开发语言·c#·wpf
one99617 小时前
.net 项目引用与 .NET Framework 项目引用之间的区别和相同
c#·.net·wpf
xcLeigh17 小时前
WPF基础 | WPF 布局系统深度剖析:从 Grid 到 StackPanel
c#·wpf
CHHC188021 小时前
ML.NET 图像分类
.net·图像分类·mlnet