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

相关推荐
普通网友2 小时前
C# 中委托和事件的深度剖析与应用场景
java·算法·c#
BearHan3 小时前
非常'肤浅'的理解MVVM
wpf
钢铁男儿4 小时前
C#结构体性能暴击指南:从内存陷阱到零损耗实战
开发语言·c#
MZZ骏马5 小时前
C#接受文件
开发语言·c#
ou.cs5 小时前
wpf 控件开发中,OnApplyTemplate 和 OnContentRendered区别
c#·.net·wpf
忧郁的蛋~8 小时前
.NET Core 实现缓存的预热的方式
缓存·c#·.net·.netcore
ou.cs1 天前
wpf 队列(Queue)在视觉树迭代查找中的作用分析
wpf
code bean1 天前
【WPF】WPF 中 `DisplayMemberPath` 与 `SelectedValuePath` 的深入理解与实战应用
windows·wpf
csdn_aspnet1 天前
C# .NET Core 源代码生成器(dotnet source generators)
c#·.netcore
时光追逐者1 天前
C#/.NET/.NET Core技术前沿周刊 | 第 42 期(2025年6.9-6.15)
c#·.net·.netcore