DiscreteInt16KeyFrame 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
public ref class DiscreteInt16KeyFrame : System::Windows::Media::Animation::Int16KeyFrame
public class DiscreteInt16KeyFrame : System.Windows.Media.Animation.Int16KeyFrame
type DiscreteInt16KeyFrame = class
inherit Int16KeyFrame
Public Class DiscreteInt16KeyFrame
Inherits Int16KeyFrame
- 继承
示例
动画的内插对动画在其持续时间内在值之间进行过渡的方式进行了描述。 通过选择动画要使用哪种关键帧类型,可以定义该关键帧段的内插方法。 有三种不同类型的内插方法:线性、离散和曲线。 此示例使用 来 DoubleAnimationUsingKeyFrames 演示这些内插类型。
以下示例使用 类可用的 DoubleAnimationUsingKeyFrames 每个不同内插方法对 的位置 Rectangle进行动画处理。
在前三秒中,使用 LinearDoubleKeyFrame 类的实例将矩形沿路径以稳定速率从其起始位置移动到 500 位置。 LinearDoubleKeyFrame 之类的线性关键帧在值之间创建平滑的线性过渡。
在第四秒结束时,使用 DiscreteDoubleKeyFrame 类的实例将矩形突然移动到下一个位置。 DiscreteDoubleKeyFrame 之类的离散关键帧在值之间创建突然跳跃。 在该示例中,矩形位于起始位置,然后突然出现在 500 位置。
在最后两秒内,使用 SplineDoubleKeyFrame 类的实例将矩形移回其起始位置。 SplineDoubleKeyFrame 之类的自由绘制曲线关键帧根据 KeySpline 属性的值在值之间创建变量过渡。 在此示例中,矩形从缓慢移动开始,然后以指数方式加快到时间段的末尾
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Media;
namespace Microsoft.Samples.KeyFrameExamples
{
/// <summary>
/// This example shows how to use the DoubleAnimationUsingKeyFrames class to
/// animate the position of an object.
/// Key frame animations enable you to create complex animations
/// by specifying multiple destination values
/// and controlling the animation's interpolation method.
/// </summary>
public class AltDoubleAnimationUsingKeyFramesExample : Page
{
public AltDoubleAnimationUsingKeyFramesExample()
{
Title = "DoubleAnimationUsingKeyFrames Example";
Background = Brushes.White;
Margin = new Thickness(20);
// Create a NameScope for this page so that
// Storyboards can be used.
NameScope.SetNameScope(this, new NameScope());
// Create a rectangle.
Rectangle aRectangle = new Rectangle();
aRectangle.Width = 100;
aRectangle.Height = 100;
aRectangle.Stroke = Brushes.Black;
aRectangle.StrokeThickness = 5;
// Create a Canvas to contain and
// position the rectangle.
Canvas containerCanvas = new Canvas();
containerCanvas.Width = 610;
containerCanvas.Height = 300;
containerCanvas.Children.Add(aRectangle);
Canvas.SetTop(aRectangle, 100);
Canvas.SetLeft(aRectangle, 10);
// Create a TranslateTransform to
// move the rectangle.
TranslateTransform animatedTranslateTransform =
new TranslateTransform();
aRectangle.RenderTransform = animatedTranslateTransform;
// Assign the TranslateTransform a name so that
// it can be targeted by a Storyboard.
this.RegisterName(
"AnimatedTranslateTransform", animatedTranslateTransform);
// Create a DoubleAnimationUsingKeyFrames to
// animate the TranslateTransform.
DoubleAnimationUsingKeyFrames translationAnimation
= new DoubleAnimationUsingKeyFrames();
translationAnimation.Duration = TimeSpan.FromSeconds(6);
// Animate from the starting position to 500
// over the first second using linear
// interpolation.
translationAnimation.KeyFrames.Add(
new LinearDoubleKeyFrame(
500, // Target value (KeyValue)
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3))) // KeyTime
);
// Animate from 500 (the value of the previous key frame)
// to 400 at 4 seconds using discrete interpolation.
// Because the interpolation is discrete, the rectangle will appear
// to "jump" from 500 to 400.
translationAnimation.KeyFrames.Add(
new DiscreteDoubleKeyFrame(
400, // Target value (KeyValue)
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4))) // KeyTime
);
// Animate from 400 (the value of the previous key frame) to 0
// over two seconds, starting at 4 seconds (the key time of the
// last key frame) and ending at 6 seconds.
translationAnimation.KeyFrames.Add(
new SplineDoubleKeyFrame(
0, // Target value (KeyValue)
KeyTime.FromTimeSpan(TimeSpan.FromSeconds(6)), // KeyTime
new KeySpline(0.6,0.0,0.9,0.0) // KeySpline
)
);
// Set the animation to repeat forever.
translationAnimation.RepeatBehavior = RepeatBehavior.Forever;
// Set the animation to target the X property
// of the object named "AnimatedTranslateTransform."
Storyboard.SetTargetName(translationAnimation, "AnimatedTranslateTransform");
Storyboard.SetTargetProperty(
translationAnimation, new PropertyPath(TranslateTransform.XProperty));
// Create a storyboard to apply the animation.
Storyboard translationStoryboard = new Storyboard();
translationStoryboard.Children.Add(translationAnimation);
// Start the storyboard after the rectangle loads.
aRectangle.Loaded += delegate(object sender, RoutedEventArgs e)
{
translationStoryboard.Begin(this);
};
Content = containerCanvas;
}
}
}
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Shapes
Imports System.Windows.Media.Animation
Imports System.Windows.Media
Namespace Microsoft.Samples.KeyFrameExamples
''' <summary>
''' This example shows how to use the DoubleAnimationUsingKeyFrames class to
''' animate the position of an object.
''' Key frame animations enable you to create complex animations
''' by specifying multiple destination values
''' and controlling the animation's interpolation method.
''' </summary>
Public Class AltDoubleAnimationUsingKeyFramesExample
Inherits Page
Public Sub New()
Title = "DoubleAnimationUsingKeyFrames Example"
Background = Brushes.White
Margin = New Thickness(20)
' Create a NameScope for this page so that
' Storyboards can be used.
NameScope.SetNameScope(Me, New NameScope())
' Create a rectangle.
Dim aRectangle As New Rectangle()
aRectangle.Width = 100
aRectangle.Height = 100
aRectangle.Stroke = Brushes.Black
aRectangle.StrokeThickness = 5
' Create a Canvas to contain and
' position the rectangle.
Dim containerCanvas As New Canvas()
containerCanvas.Width = 610
containerCanvas.Height = 300
containerCanvas.Children.Add(aRectangle)
Canvas.SetTop(aRectangle, 100)
Canvas.SetLeft(aRectangle, 10)
' Create a TranslateTransform to
' move the rectangle.
Dim animatedTranslateTransform As New TranslateTransform()
aRectangle.RenderTransform = animatedTranslateTransform
' Assign the TranslateTransform a name so that
' it can be targeted by a Storyboard.
Me.RegisterName("AnimatedTranslateTransform", animatedTranslateTransform)
' Create a DoubleAnimationUsingKeyFrames to
' animate the TranslateTransform.
Dim translationAnimation As New DoubleAnimationUsingKeyFrames()
translationAnimation.Duration = TimeSpan.FromSeconds(6)
' Animate from the starting position to 500
' over the first second using linear
' interpolation.
translationAnimation.KeyFrames.Add(New LinearDoubleKeyFrame(500, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(3)))) ' KeyTime - Target value (KeyValue)
' Animate from 500 (the value of the previous key frame)
' to 400 at 4 seconds using discrete interpolation.
' Because the interpolation is discrete, the rectangle will appear
' to "jump" from 500 to 400.
translationAnimation.KeyFrames.Add(New DiscreteDoubleKeyFrame(400, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4)))) ' KeyTime - Target value (KeyValue)
' Animate from 400 (the value of the previous key frame) to 0
' over two seconds, starting at 4 seconds (the key time of the
' last key frame) and ending at 6 seconds.
translationAnimation.KeyFrames.Add(New SplineDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(6)), New KeySpline(0.6,0.0,0.9,0.0))) ' KeySpline - KeyTime - Target value (KeyValue)
' Set the animation to repeat forever.
translationAnimation.RepeatBehavior = RepeatBehavior.Forever
' Set the animation to target the X property
' of the object named "AnimatedTranslateTransform."
Storyboard.SetTargetName(translationAnimation, "AnimatedTranslateTransform")
Storyboard.SetTargetProperty(translationAnimation, New PropertyPath(TranslateTransform.XProperty))
' Create a storyboard to apply the animation.
Dim translationStoryboard As New Storyboard()
translationStoryboard.Children.Add(translationAnimation)
' Start the storyboard after the rectangle loads.
AddHandler aRectangle.Loaded, Sub(sender As Object, e As RoutedEventArgs) translationStoryboard.Begin(Me)
Content = containerCanvas
End Sub
End Class
End Namespace
<!-- This example shows how to use the DoubleAnimationUsingKeyFrames to
animate the position of an object.
Key frame animations enable you to create complex animations
by specifying multiple destination values
and controlling the animation's interpolation method.
-->
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="DoubleAnimationUsingKeyFrames Example"
Background="White" Margin="20">
<Canvas Width="610" Height="300">
<!-- The position of this rectangle is animated using
a key frame animation. -->
<Rectangle
Canvas.Top="100"
Canvas.Left="10"
Height="100"
Width="100"
Stroke="Black"
StrokeThickness="5">
<Rectangle.RenderTransform>
<TranslateTransform x:Name="AnimatedTranslateTransform" />
</Rectangle.RenderTransform>
<Rectangle.Triggers>
<EventTrigger RoutedEvent="Rectangle.Loaded">
<BeginStoryboard>
<Storyboard>
<!-- Animate the TranslateTransform.X property using 3 KeyFrames
which animates the rectangle along a straight line.
This animation repeats indefinitely. -->
<DoubleAnimationUsingKeyFrames
Storyboard.TargetName="AnimatedTranslateTransform"
Storyboard.TargetProperty="X"
Duration="0:0:6"
RepeatBehavior="Forever">
<!-- 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>
</BeginStoryboard>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
</Canvas>
</Page>
并非每个 <Type>AnimationUsingKeyFrames 类都支持所有内插方法。 有关详细信息,请参阅关键帧动画概述。
注解
此类用作 的 Int16KeyFrameCollection 一部分,与 结合使用, Int16AnimationUsingKeyFrames 以沿一组关键帧对属性值进行动画处理 Int16 。
关键帧定义它所属的 段 Int16AnimationUsingKeyFrames 。 每个关键帧都有一个目标和 Value 一个 KeyTime。 指定 KeyTime 应到达关键帧的时间 Value 。 关键帧从上一个关键帧的目标值到其自己的目标值进行动画处理。 它从上一个关键帧结束时开始,在达到其自己的关键时间时结束。
离散关键帧(如 DiscreteInt16KeyFrame )在值之间创建突然“跳转”, (无内插) 。 换句话说,动画属性在达到关键帧的关键时间之前不会更改,此时动画属性突然变为目标值。
构造函数
DiscreteInt16KeyFrame() |
初始化 DiscreteInt16KeyFrame 类的新实例。 |
DiscreteInt16KeyFrame(Int16) |
使用指定的结束值初始化 DiscreteInt16KeyFrame 类的新实例。 |
DiscreteInt16KeyFrame(Int16, KeyTime) |
使用指定的结束值和关键时间初始化 DiscreteInt16KeyFrame 类的新实例。 |
属性
CanFreeze |
获取一个值,该值指示是否可将对象变为不可修改。 (继承自 Freezable) |
DependencyObjectType |
DependencyObjectType获取包装此实例的 CLR 类型的 。 (继承自 DependencyObject) |
Dispatcher |
获取与此 Dispatcher 关联的 DispatcherObject。 (继承自 DispatcherObject) |
IsFrozen |
获取一个值,该值指示对象当前是否可修改。 (继承自 Freezable) |
IsSealed |
获取一个值,该值指示此实例当前是否为密封的(只读)。 (继承自 DependencyObject) |
KeyTime |
获取或设置关键帧的目标 Value 应到达的时间。 (继承自 Int16KeyFrame) |
Value |
获取或设置关键帧的目标值。 (继承自 Int16KeyFrame) |
方法
事件
Changed |
在修改 Freezable 或其包含的对象时发生。 (继承自 Freezable) |
显式接口实现
IKeyFrame.Value |
获取或设置与 KeyTime 实例关联的值。 (继承自 Int16KeyFrame) |