.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>
相关推荐
liyongqiangcc4 小时前
了解 ASP.NET Core 中的中间件
.net
Kiros_Jiang7 小时前
开源低代码平台-Microi吾码 打印引擎使用
javascript·开源·json·.net·pip
web1478621072310 小时前
C# .Net Web 路由相关配置
前端·c#·.net
明耀11 小时前
WPF TabControl 设置item不能点击
wpf
军训猫猫头13 小时前
20.抽卡只有金,带保底(WPF) C#
ui·c#·wpf
明耀13 小时前
WPF 设置平均布局 如果隐藏的话,能够自动扩展
wpf
数据的世界011 天前
.NET开发人员学习书籍推荐
学习·.net
paixiaoxin1 天前
CV-OCR经典论文解读|An Empirical Study of Scaling Law for OCR/OCR 缩放定律的实证研究
人工智能·深度学习·机器学习·生成对抗网络·计算机视觉·ocr·.net
晚安苏州1 天前
WPF DataTemplate 数据模板
wpf
1900431 天前
.NET重点
.net