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

相关推荐
geats人山人海1 小时前
c# 第九章 record
开发语言·c#
-银雾鸢尾-2 小时前
C#中的抽象类与抽象方法
开发语言·c#
liuxiaowei33 小时前
Winform+WPF双框架实战:喷涂工艺SCADA上位机从0到1搭建(附采集监控源码+车间踩坑实录)
大数据·hadoop·wpf
影寂ldy3 小时前
C# Task 进阶:WaitAll / WaitAny / WhenAll / WhenAny
开发语言·c#
咏方舟【长江支流】3 小时前
【编程】(1)-跨平台跨语言C#、Java、鸿蒙ArkTS三端通用实体接口
java·c#·ai编程·harmonyos·arkts·咏方舟-长江支流·用宝框架
o5278831844 小时前
校园一体化管理系统2.1、基于整洁四层架构 + DDD+CQRS 项目目录解读
后端·架构·c#·asp.net·visual studio
农村小镇哥1 天前
C#中的字符串格式化
服务器·开发语言·c#
czhc11400756631 天前
719:StartPoint;Margin;ResourceDictionar;Component.model;lds;
c#
贺国亚1 天前
模型训练-分布式与GPU调度
分布式·wpf