语言

DiscreteDoubleKeyFrame 类

定义

使用离散值从上一关键帧的 Double 值到其自己的 值 进行动画处理。

public ref class DiscreteDoubleKeyFrame sealed : DoubleKeyFrame
/// [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 DiscreteDoubleKeyFrame final : DoubleKeyFrame
[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 DiscreteDoubleKeyFrame : DoubleKeyFrame
Public NotInheritable Class DiscreteDoubleKeyFrame
Inherits DoubleKeyFrame
<DiscreteDoubleKeyFrame .../>
继承
Object Platform::Object IInspectable DependencyObject DoubleKeyFrame DiscreteDoubleKeyFrame
属性

示例

此 XAML 示例跨屏幕移动一个矩形。 该示例使用 DoubleAnimationUsingKeyFrames 类对应用于矩形的 TranslateTransform 的 X 属性进行动画处理。 此动画采用以下方式使用三个关键帧:

  1. 在前三秒内,它使用 LinearDoubleKeyFrame 类的实例将矩形沿路径以稳定速率从起始位置移动到 500 位置。 线性关键帧(如 LinearDoubleKeyFrame )在值之间创建平滑线性转换。
  2. 第四秒结束时,它使用 DiscreteDoubleKeyFrame 类的实例突然将矩形移动到下一个位置。 离散关键帧(如 DiscreteDoubleKeyFrame)在值之间突然跳跃。 在此示例中,矩形位于起始位置,然后突然出现在 500 位置。
  3. 在最后两秒内,它使用 SplineDoubleKeyFrame 类的实例将矩形移回其起始位置。 SplineDoubleKeyFrame 等样条关键帧根据 KeySpline 属性的值在值之间创建变量转换。 在此示例中,矩形首先缓慢移动,然后以指数方式加速到时间段的末尾。
<StackPanel>
    <StackPanel.Resources>
        <Storyboard x:Name="myStoryboard">

            <!-- Animate the TranslateTransform's X property
             from 0 to 350, then 50,
             then 200 over 10 seconds. -->
            <DoubleAnimationUsingKeyFrames
          Storyboard.TargetName="MyAnimatedTranslateTransform"
          Storyboard.TargetProperty="X"
          Duration="0:0:10" EnableDependentAnimation="True">

                <!-- Using a LinearDoubleKeyFrame, the rectangle moves 
                 steadily from its starting position to 500 over 
                 the first 3 seconds.  -->
                <LinearDoubleKeyFrame Value="500" KeyTime="0:0:3" />

                <!-- Using a DiscreteDoubleKeyFrame, the rectangle suddenly 
                 appears at 400 after the fourth second of the animation. -->
                <DiscreteDoubleKeyFrame Value="400" KeyTime="0:0:4" />

                <!-- Using a SplineDoubleKeyFrame, the rectangle moves 
                 back to its starting point. The
                 animation starts out slowly at first and then speeds up. 
                 This KeyFrame ends after the 6th
                 second. -->
                <SplineDoubleKeyFrame KeySpline="0.6,0.0 0.9,0.00" Value="0" KeyTime="0:0:6" />

            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </StackPanel.Resources>
    <Rectangle Fill="Blue" Width="50" Height="50" Loaded="Start_Animation">
        <Rectangle.RenderTransform>
            <TranslateTransform x:Name="MyAnimatedTranslateTransform" 
             X="0" Y="0" />
        </Rectangle.RenderTransform>
    </Rectangle>
</StackPanel>
// Start the animation when the object loads
private void Start_Animation(object sender, RoutedEventArgs e)
{
    myStoryboard.Begin();
}

注解

关键帧动画允许在动画时间线的不同点到达多个目标值。 换句话说,每个关键帧可以指定不同的中间值,到达的最后一个关键帧是最终动画值。 通过指定要进行动画处理的多个值,可以制作更复杂的动画。 可以在同一关键帧集合中混合离散、线性和样条关键帧。

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

构造函数

名称 说明
DiscreteDoubleKeyFrame()

初始化 DiscreteDoubleKeyFrame 类的新实例。

属性

名称 说明
Dispatcher

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

(继承自 DependencyObject)
DispatcherQueue

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

(继承自 DependencyObject)
KeyTime

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

(继承自 DoubleKeyFrame)
Value

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

(继承自 DoubleKeyFrame)

方法

名称 说明
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)

适用于

另请参阅