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

相关推荐
酷酷的身影1 小时前
Managers/APConfigManager.cs
开发语言·ui·c#
贾斯汀frank13 小时前
C# 15 类型系统改进:Union Types
开发语言·windows·c#
时代的狂15 小时前
如何理解 C# 的 async 和 await
c#·.netcore·async·await
国服第二切图仔16 小时前
HarmonyOS APP《画伴梦工厂》开发第60篇-分布式软总线2.0——多设备协同新范式
分布式·wpf·harmonyos
xiaoshuaishuai818 小时前
C# AI实现PR处理、单元测试
开发语言·c#·log4j
LONGZHIQIN18 小时前
C#基础复习笔记
开发语言·笔记·c#
时代的狂20 小时前
如何理解 C#/.NET 的依赖注入与生命周期
c#·.net·依赖注入·控制反转
品尚公益团队21 小时前
C#在asp.net网页开发中的带cookie登录实现
前端·c#·asp.net
吴可可12321 小时前
C#自定义CAD多段线零件实体
c#
CallmeFoureyes21 小时前
使用 C# 提取 Word 文档中的表格数据
开发语言·c#·word