WPF关键帧动画

背景:要实现动画已经有关键动画了,但是关键动画如果动画比较复杂,那么就需要重复写多个DoubleAnimation。如果使用上关键帧就可以少写几遍Storyboard里面的属性

普通动画:

XML 复制代码
<DoubleAnimation From="0" To="30" Duration="0:0:2" BeginTime="0:0:3"
                 Storyboard.TargetName="" Storyboard.TargetProperty="">

使用上关键帧的动画:

XML 复制代码
<Rectangle x:Name="myRect" Width="50" Height="50" HorizontalAlignment="Left" Fill="Blue">
    <Rectangle.RenderTransform>
        <TranslateTransform x:Name="myTranslate" X="0" Y="0"/>
    </Rectangle.RenderTransform>

    <Rectangle.Triggers>
        <EventTrigger RoutedEvent="Rectangle.MouseLeftButtonDown">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimationUsingKeyFrames 
                        Storyboard.TargetName="myTranslate" 
                        Storyboard.TargetProperty="X"
                        Duration="0:0:10">
                        <LinearDoubleKeyFrame Value="100" KeyTime="30%"/>
                        <LinearDoubleKeyFrame Value="300" KeyTime="60%"/>
                        <LinearDoubleKeyFrame Value="700" KeyTime="70%"/>
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Rectangle.Triggers>
</Rectangle>

-- 这里体现的是关键帧作用于X坐标

更加细节可以看痕迹大神的文章:https://www.cnblogs.com/zh7791/p/12897696.html

相关推荐
小金子会发光3 小时前
C# WinForms 基于 Socket 手搓 Modbus TCP 调试助手(支持 01/02/03/04/05/06/0F/10)
c#·socket·plc·modbus tcp·工业通信
慧都小妮子4 小时前
PDF图片提取总“褪色“?Aspose.PDF 多层级提取能力详解
pdf·c#·.net·图片处理·文档处理·色彩空间
-银雾鸢尾-6 小时前
C#中的反射关键类-Type
开发语言·c#
淡海水8 小时前
15-07-YooAsset面试篇-Unity性能优化与内存管理
java·unity·面试·性能优化·c#·游戏引擎
dalong108 小时前
WPF:3D型材模型
3d·wpf
离陌在学C#8 小时前
C# 多态:面向对象编程的核心特性详解
开发语言·c#
一念春风9 小时前
文件透明加密(C、C#)
c语言·c#·wpf
hez201020 小时前
.NET 11 Runtime Async 详解
c#·.net·.net core
猿长大人1 天前
C# | Serilog 新手入门
开发语言·c#·.net·log
在世修行1 天前
从零打造 C# 工业视觉检测系统(七):串口通信 SerialPort 封装与开发
开发语言·c#·modbus rtu·rs232/rs485