SplineColorKeyFrame 类

定义

使用条带内插将上一个关键帧的 Color 值设置为其自己的 进行动画处理。

public ref class SplineColorKeyFrame sealed : ColorKeyFrame
/// [Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SplineColorKeyFrame final : ColorKeyFrame
[Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class SplineColorKeyFrame : ColorKeyFrame
Public NotInheritable Class SplineColorKeyFrame
Inherits ColorKeyFrame
<SplineColorKeyFrame .../>
继承
Object Platform::Object IInspectable DependencyObject ColorKeyFrame SplineColorKeyFrame
属性

示例

此 XAML 示例使用 ColorAnimationUsingKeyFrames 类对 StackPanelBackground 属性进行动画处理。 此动画按以下方式使用三个关键帧:

  1. 在前两秒内, LinearColorKeyFrame 逐渐将颜色从绿色更改为红色。 线性关键帧(如 LinearColorKeyFrame )在值之间创建平滑的线性过渡。
  2. 在下半秒结束时, DiscreteColorKeyFrame 快速将颜色从红色更改为黄色。 离散关键帧(如 DiscreteColorKeyFrame )会在值之间产生突然变化;动画发生得很快,值之间根本没有内插。
  3. 在最后两秒内,SplineColorKeyFrame 再次更改颜色,这次从黄色变回绿色。 样条关键帧(如 SplineColorKeyFrame)根据 KeySpline 属性的值创建值之间的可变转换。 KeySpline 提供了一种在动画持续时间内将时间与值的关系更改为非线性的方法,具体而言,关系可能是单个关键帧难以生成的曲线。 在此示例中,颜色变化开始时缓慢,然后以指数方式加速,直到时间段结束。
<StackPanel x:Name="myStackPanel" Background="Red"
Loaded="Start_Animation">
    <StackPanel.Resources>
        <Storyboard x:Name="colorStoryboard">

            <ColorAnimationUsingKeyFrames Storyboard.TargetName="myStackPanel" 
      Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)">
                
                <!-- Go from green to red in the first 2 seconds. LinearColorKeyFrame creates
                a smooth, linear animation between values. -->
                <LinearColorKeyFrame Value="Blue" KeyTime="00:00:02" />

                <!-- In the next half second, go to yellow. DiscreteColorKeyFrame creates a 
                sudden jump between values. -->
                <DiscreteColorKeyFrame Value="Yellow" KeyTime="00:00:2.5" />

                <!-- In the final 2 seconds of the animation, go from yellow back to green. SplineColorKeyFrame 
                creates a variable transition between values depending on the KeySpline property. In this example,
                the animation starts off slow but toward the end of the time segment, it speeds up exponentially.-->
                <SplineColorKeyFrame Value="Green" KeyTime="00:00:4.5" KeySpline="0.6,0.0 0.9,0.00" />

            </ColorAnimationUsingKeyFrames>
        </Storyboard>
    </StackPanel.Resources>
</StackPanel>
// Start the animation when the object loads
private void Start_Animation(object sender, RoutedEventArgs e)
{
    colorStoryboard.Begin();
}

注解

关键帧动画允许沿动画时间线到达一个点的多个目标值。 换句话说,每个关键帧可以指定一个不同的中间值,并且到达的最后一个关键帧为最终动画值。 通过指定多个值来创建动画,你可以做出更复杂的动画。 可以在同一关键帧集合中混合离散、线性和样条关键帧。

有关如何使用关键帧动画的详细信息,请参阅 关键帧动画和缓动函数动画

构造函数

SplineColorKeyFrame()

初始化 SplineColorKeyFrame 类的新实例。

属性

Dispatcher

始终在Windows 应用 SDK应用中返回 null 。 请改用 DispatcherQueue

(继承自 DependencyObject)
DispatcherQueue

获取 DispatcherQueue 与此 对象关联的 。 DispatcherQueue表示可以访问 DependencyObject UI 线程上的 的功能,即使代码是由非 UI 线程启动的。

(继承自 DependencyObject)
KeySpline

获取或设置两个控制点,它们定义此关键帧的动画进度。

KeySplineProperty

标识 KeySpline 依赖属性。

KeyTime

获取或设置应达到关键帧的目标 的时间。

(继承自 ColorKeyFrame)
Value

获取或设置关键帧的目标值。

(继承自 ColorKeyFrame)

方法

ClearValue(DependencyProperty)

清除依赖属性的本地值。

(继承自 DependencyObject)
GetAnimationBaseValue(DependencyProperty)

返回为依赖属性建立的任何基值,该基值适用于动画未处于活动状态的情况。

(继承自 DependencyObject)
GetValue(DependencyProperty)

DependencyObject 返回依赖属性的当前有效值。

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

如果设置了本地值,则返回依赖属性的本地值。

(继承自 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

注册一个通知函数,用于侦听此 DependencyObject 实例上特定 DependencyProperty 的更改。

(继承自 DependencyObject)
SetValue(DependencyProperty, Object)

设置 DependencyObject 上依赖属性的本地值。

(继承自 DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

取消以前通过调用 RegisterPropertyChangedCallback 注册的更改通知。

(继承自 DependencyObject)

适用于

另请参阅