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

相关推荐
SunnyDays101121 小时前
使用 C# 实现 Excel 与 DataTable 相互转换
c#·excel转datatable·datatable转excel
獨枭1 天前
C# 本地项目引用失效与恢复全攻略
开发语言·c#·visual studio
清风与日月1 天前
c# 上位机作为控制端与下位机通信方式
单片机·嵌入式硬件·c#
烛阴1 天前
从零开始掌握C#核心:变量与数据类型
前端·c#
yue0081 天前
C# 生成指定位数的编号
开发语言·c#
红黑色的圣西罗1 天前
C# List.Sort方法总结
开发语言·c#
夏霞2 天前
c# ASP.NET Core SignalR 客户端配置自动重连次数
c#·.netcore
2501_930707782 天前
使用C#代码在 Word 文档中查找并替换文本
开发语言·c#·word
一个帅气昵称啊2 天前
在.NET中使用RAG检索增强AI基于Qdrant的矢量化数据库
ai·性能优化·c#·.net·rag·qdrant