DiscreteInt16KeyFrame 類別

定義

使用離散插補,從上一個主要畫面格的 Int16 值以動畫顯示到其自有的 Value

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

  1. 在前三秒內,使用 類別的 LinearDoubleKeyFrame 實例,將矩形沿著路徑以穩定速率從其起始位置移至 500 位置。 線性主要畫面格,例如 LinearDoubleKeyFrame 在值之間建立平滑的線性轉換。

  2. 在第四秒結束時,使用 類別的 DiscreteDoubleKeyFrame 實例突然將矩形移至下一個位置。 不同的主要畫面格,例如 DiscreteDoubleKeyFrame 在值之間突然跳躍。 在此範例中,矩形位在起始位置,接著會突然出現在 500 位置。

  3. 在最後兩秒內,使用 類別的 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 段。 每個主要畫面格都有目標和 ValueKeyTimeKeyTime指定應該到達主要畫面格 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)

方法

CheckAccess()

判斷呼叫的執行是否可以存取這個 DispatcherObject

(繼承來源 DispatcherObject)
ClearValue(DependencyProperty)

清除屬性的區域數值。 要清除的屬性是由 DependencyProperty 識別項所指定。

(繼承來源 DependencyObject)
ClearValue(DependencyPropertyKey)

清除唯讀屬性的區域數值。 要清除的屬性是由 DependencyPropertyKey 所指定。

(繼承來源 DependencyObject)
Clone()

建立這個 Freezable 的可修改複製,製作這個物件值的深層複製。 當複製這個物件的相依性屬性時,這個方法會複製運算式 (但可能已不再解析),但不會複製動畫或其目前值。

(繼承來源 Freezable)
CloneCore(Freezable)

使用基底 (非動畫) 屬性值,將執行個體設為指定 Freezable 的複製品 (深層複製)。

(繼承來源 Freezable)
CloneCurrentValue()

使用 Freezable 的目前值,建立它的可修改複製品 (深層複本)。

(繼承來源 Freezable)
CloneCurrentValueCore(Freezable)

使用目前的屬性值,讓執行個體成為指定之 Freezable 的可修改複本 (深層複本)。

(繼承來源 Freezable)
CoerceValue(DependencyProperty)

強制轉型所指定相依性屬性的值。 完成方式是叫用存在於呼叫 DependencyObject 之相依性屬性的屬性中繼資料中所指定的任何 CoerceValueCallback 函式。

(繼承來源 DependencyObject)
CreateInstance()

初始化 Freezable 類別的新執行個體。

(繼承來源 Freezable)
CreateInstanceCore()

建立 DiscreteInt16KeyFrame 的新執行個體。

Equals(Object)

判斷提供的 DependencyObject 和目前的 DependencyObject 是否相等。

(繼承來源 DependencyObject)
Freeze()

將目前的物件設為不可修改,並將其 IsFrozen 屬性設定為 true

(繼承來源 Freezable)
FreezeCore(Boolean)

Freezable 物件設為不可修改的,或測試是否可以將它設為不可修改的。

(繼承來源 Freezable)
GetAsFrozen()

使用基底 (非動畫) 屬性值,建立 Freezable 的凍結複本。 因為複本已凍結,所以會以傳址方式複製任何凍結子物件。

(繼承來源 Freezable)
GetAsFrozenCore(Freezable)

使用基底 (非動畫) 屬性值,將執行個體設為指定 Freezable 的凍結複本。

(繼承來源 Freezable)
GetCurrentValueAsFrozen()

使用目前屬性值,建立 Freezable 的凍結複本。 因為複本已凍結,所以會以傳址方式複製任何凍結子物件。

(繼承來源 Freezable)
GetCurrentValueAsFrozenCore(Freezable)

將目前執行個體設為所指定 Freezable 的凍結複本。 如果物件具有動畫相依性屬性,則會複製其目前的動畫值。

(繼承來源 Freezable)
GetHashCode()

取得這個 DependencyObject 的雜湊碼。

(繼承來源 DependencyObject)
GetLocalValueEnumerator()

建立特定的列舉值,以判斷哪些相依性屬性在此 DependencyObject 上具有本機設定的值。

(繼承來源 DependencyObject)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetValue(DependencyProperty)

傳回 DependencyObject 的這個執行個體上之相依性屬性的目前有效值。

(繼承來源 DependencyObject)
InterpolateValue(Int16, Double)

傳回在提供漸次累加時,特定主要畫面格的插補值。

(繼承來源 Int16KeyFrame)
InterpolateValueCore(Int16, Double)

使用離散插補在先前的主要畫面格值與目前的主要畫面格值之間進行轉換。

InvalidateProperty(DependencyProperty)

重新評估指定相依性屬性的有效值。

(繼承來源 DependencyObject)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
OnChanged()

目前的 Freezable 物件遭到修改時進行呼叫。

(繼承來源 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject)

確定已為剛剛設定的 DependencyObjectType 資料成員,建立適當的內容指標。

(繼承來源 Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

此成員支援Windows Presentation Foundation (WPF) 基礎結構,而且不適合直接從程式碼使用。

(繼承來源 Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

覆寫 OnPropertyChanged(DependencyPropertyChangedEventArgs)DependencyObject 實作也可以叫用任何 Changed 處理常式,以回應類型 Freezable 的變更相依性屬性。

(繼承來源 Freezable)
ReadLocalValue(DependencyProperty)

傳回相依性屬性的區域值 (如果存在)。

(繼承來源 DependencyObject)
ReadPreamble()

確定 Freezable 是從有效的執行緒進行存取。 如果 API 會讀取非相依性屬性的資料成員,則 Freezable 的繼承者必須在該 API 的開頭呼叫這個方法。

(繼承來源 Freezable)
SetCurrentValue(DependencyProperty, Object)

設定相依性屬性的值,而不需要變更其值來源。

(繼承來源 DependencyObject)
SetValue(DependencyProperty, Object)

設定相依性屬性的區域值 (由相依性屬性的識別碼所指定)。

(繼承來源 DependencyObject)
SetValue(DependencyPropertyKey, Object)

設定唯讀相依性屬性的區域數值 (由相依性屬性的 DependencyPropertyKey 識別項所指定)。

(繼承來源 DependencyObject)
ShouldSerializeProperty(DependencyProperty)

傳回值,這個值表示序列化程序是否應該序列化所提供相依性屬性的值。

(繼承來源 DependencyObject)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)
VerifyAccess()

請強制執行可以存取這個 DispatcherObject 的呼叫執行緒。

(繼承來源 DispatcherObject)
WritePostscript()

引發 FreezableChanged 事件,並叫用其 OnChanged() 方法。 在任何 API 修改未以相依性屬性儲存的類別成員之後,衍生自 Freezable 的類別應該在 API 的結尾呼叫這個方法。

(繼承來源 Freezable)
WritePreamble()

確認 Freezable 未凍結,而且是從有效的執行緒內容進行存取。 在任何 API 將資料寫入至非相依性屬性的資料成員之前,Freezable 繼承者應該在 API 的開頭呼叫這個方法。

(繼承來源 Freezable)

事件

Changed

發生於 Freezable 或所含的物件遭到修改時。

(繼承來源 Freezable)

明確介面實作

IKeyFrame.Value

取得或設定與 KeyTime 執行個體相關聯的值。

(繼承來源 Int16KeyFrame)

適用於

另請參閱