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 段。 每個主要畫面格都有目標和 ValueKeyTime 。 KeyTime指定應該到達主要畫面格 Value 的時間。 主要畫面格會從前一個主要畫面格的目標值到其本身的目標值產生動畫效果。 它會在上一個主要畫面格結束時開始,並在到達自己的主要時間時結束。
不同的主要畫面格,例如 DiscreteInt16KeyFrame 在值之間突然「跳躍」, (無插補點) 。 換句話說,動畫屬性在到達主要畫面格的主要時間之前不會變更,此時動畫屬性突然變成目標值。
建構函式
DiscreteInt16KeyFrame() |
初始化 DiscreteInt16KeyFrame 類別的新執行個體。 |
DiscreteInt16KeyFrame(Int16) |
使用指定的結束值,初始化 DiscreteInt16KeyFrame 類別的新執行個體。 |
DiscreteInt16KeyFrame(Int16, KeyTime) |
使用指定結束值和 Key Time,初始化 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) |