Condividi tramite


DiscreteInt16KeyFrame Classe

Definizione

Aggiunge un'animazione dal Int16 valore del fotogramma chiave precedente al proprio Value usando l'interpolazione discreta.

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
Ereditarietà

Esempio

L'interpolazione di un'animazione descrive il modo in cui un'animazione passa tra i valori nel corso della durata. Selezionando il tipo di fotogramma chiave usato con l'animazione, è possibile definire il metodo di interpolazione per il segmento di fotogrammi chiave. Esistono tre diversi tipi di metodi di interpolazione: lineare, discreto e splined. In questo esempio viene usato un oggetto DoubleAnimationUsingKeyFrames per illustrare questi tipi di interpolazione.

Nell'esempio seguente vengono usati ognuno dei diversi metodi di interpolazione disponibili per la DoubleAnimationUsingKeyFrames classe per animare la posizione di un oggetto Rectangle.

  1. Durante i primi tre secondi, usa un'istanza della LinearDoubleKeyFrame classe per spostare il rettangolo lungo un percorso a una velocità costante dalla posizione iniziale alla posizione 500. Fotogrammi chiave lineari come LinearDoubleKeyFrame creare una transizione lineare uniforme tra valori.

  2. Alla fine del quarto secondo, usa un'istanza della DiscreteDoubleKeyFrame classe per spostare improvvisamente il rettangolo nella posizione successiva. Fotogrammi chiave discreti come DiscreteDoubleKeyFrame creare salti improvvisi tra valori. In questo esempio, il rettangolo si trova nella posizione iniziale e quindi improvvisamente viene visualizzato nella posizione 500.

  3. Negli ultimi due secondi, usa un'istanza della SplineDoubleKeyFrame classe per spostare nuovamente il rettangolo nella posizione iniziale. Fotogrammi chiave spline come SplineDoubleKeyFrame creare una transizione di variabile tra valori in base al valore della KeySpline proprietà. In questo esempio, il rettangolo inizia spostandosi lentamente e quindi accelera in modo esponenziale verso la fine del segmento di tempo

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>

Non tutte le <classi Type>AnimationUsingKeyFrames supportano tutti i metodi di interpolazione. Per altre informazioni, vedere cenni preliminari sulle animazioniKey-Frame.

Commenti

Questa classe viene utilizzata come parte di un Int16KeyFrameCollection insieme a per Int16AnimationUsingKeyFrames animare un Int16 valore della proprietà lungo un set di fotogrammi chiave.

Un fotogramma chiave definisce un segmento dell'oggetto Int16AnimationUsingKeyFrames a cui appartiene. Ogni fotogramma chiave ha una destinazione Value e un oggetto KeyTime. KeyTime Specifica l'ora in cui deve essere raggiunto il fotogramma Value chiave. Un fotogramma chiave viene animato dal valore di destinazione del fotogramma chiave precedente al proprio valore di destinazione. Inizia quando termina il fotogramma chiave precedente e termina quando viene raggiunto il proprio tempo di chiave.

Fotogrammi chiave discreti come DiscreteInt16KeyFrame creare "salti" improvvisi tra valori (nessuna interpolazione). In altre parole, la proprietà animata non cambia fino a quando non viene raggiunto il tempo di chiave del fotogramma chiave, a quel punto la proprietà animata passa improvvisamente al valore di destinazione.

Costruttori

Nome Descrizione
DiscreteInt16KeyFrame()

Inizializza una nuova istanza della classe DiscreteInt16KeyFrame.

DiscreteInt16KeyFrame(Int16, KeyTime)

Inizializza una nuova istanza della DiscreteInt16KeyFrame classe con il valore finale e l'ora della chiave specificati.

DiscreteInt16KeyFrame(Int16)

Inizializza una nuova istanza della DiscreteInt16KeyFrame classe con il valore finale specificato.

Proprietà

Nome Descrizione
CanFreeze

Ottiene un valore che indica se l'oggetto può essere reso non modificabile.

(Ereditato da Freezable)
DependencyObjectType

Ottiene l'oggetto DependencyObjectType che esegue il wrapping del tipo CLR di questa istanza.

(Ereditato da DependencyObject)
Dispatcher

Ottiene l'oggetto DispatcherDispatcherObject a cui è associato.

(Ereditato da DispatcherObject)
IsFrozen

Ottiene un valore che indica se l'oggetto è attualmente modificabile.

(Ereditato da Freezable)
IsSealed

Ottiene un valore che indica se questa istanza è attualmente sealed (sola lettura).

(Ereditato da DependencyObject)
KeyTime

Ottiene o imposta l'ora in cui deve essere raggiunta la destinazione Value del fotogramma chiave.

(Ereditato da Int16KeyFrame)
Value

Ottiene o imposta il valore di destinazione del fotogramma chiave.

(Ereditato da Int16KeyFrame)

Metodi

Nome Descrizione
CheckAccess()

Determina se il thread chiamante ha accesso a questo DispatcherObjectoggetto .

(Ereditato da DispatcherObject)
ClearValue(DependencyProperty)

Cancella il valore locale di una proprietà. La proprietà da cancellare viene specificata da un DependencyProperty identificatore.

(Ereditato da DependencyObject)
ClearValue(DependencyPropertyKey)

Cancella il valore locale di una proprietà di sola lettura. La proprietà da cancellare viene specificata da un oggetto DependencyPropertyKey.

(Ereditato da DependencyObject)
Clone()

Crea un clone modificabile dell'oggetto Freezable, eseguendo copie complete dei valori dell'oggetto. Quando si copiano le proprietà di dipendenza dell'oggetto, questo metodo copia le espressioni (che potrebbero non essere più risolte) ma non le animazioni o i relativi valori correnti.

(Ereditato da Freezable)
CloneCore(Freezable)

Rende l'istanza un clone (copia completa) dell'oggetto specificato Freezable usando valori di proprietà di base (non animati).

(Ereditato da Freezable)
CloneCurrentValue()

Crea un clone modificabile (copia completa) dell'oggetto Freezable utilizzando i relativi valori correnti.

(Ereditato da Freezable)
CloneCurrentValueCore(Freezable)

Rende l'istanza un clone modificabile (copia completa) dell'oggetto specificato Freezable utilizzando i valori delle proprietà correnti.

(Ereditato da Freezable)
CoerceValue(DependencyProperty)

Forza il valore della proprietà di dipendenza specificata. A tale scopo, richiamare qualsiasi CoerceValueCallback funzione specificata nei metadati della proprietà per la proprietà di dipendenza così come esiste nella chiamata DependencyObjectdi .

(Ereditato da DependencyObject)
CreateInstance()

Inizializza una nuova istanza della classe Freezable.

(Ereditato da Freezable)
CreateInstanceCore()

Crea una nuova istanza di DiscreteInt16KeyFrame.

Equals(Object)

Determina se un oggetto specificato DependencyObject è equivalente all'oggetto corrente DependencyObject.

(Ereditato da DependencyObject)
Freeze()

Rende l'oggetto corrente non modificabile e imposta la relativa IsFrozen proprietà su true.

(Ereditato da Freezable)
FreezeCore(Boolean)

Rende l'oggetto Freezable non modificabile o verifica se può essere reso non modificabile.

(Ereditato da Freezable)
GetAsFrozen()

Crea una copia bloccata della proprietà , utilizzando i valori della Freezableproprietà base (non animati). Poiché la copia è bloccata, tutti gli oggetti secondari bloccati vengono copiati in base al riferimento.

(Ereditato da Freezable)
GetAsFrozenCore(Freezable)

Rende l'istanza un clone bloccato dell'oggetto specificato Freezable utilizzando valori di proprietà di base (non animati).

(Ereditato da Freezable)
GetCurrentValueAsFrozen()

Crea una copia bloccata dell'oggetto utilizzando i valori correnti delle Freezable proprietà. Poiché la copia è bloccata, tutti gli oggetti secondari bloccati vengono copiati in base al riferimento.

(Ereditato da Freezable)
GetCurrentValueAsFrozenCore(Freezable)

Rende l'istanza corrente un clone bloccato dell'oggetto specificato Freezable. Se l'oggetto ha proprietà di dipendenza animate, i valori animati correnti vengono copiati.

(Ereditato da Freezable)
GetHashCode()

Ottiene un codice hash per l'oggetto DependencyObject.

(Ereditato da DependencyObject)
GetLocalValueEnumerator()

Crea un enumeratore specializzato per determinare quali proprietà di dipendenza hanno valori impostati localmente in questo DependencyObjectoggetto .

(Ereditato da DependencyObject)
GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
GetValue(DependencyProperty)

Restituisce il valore effettivo corrente di una proprietà di dipendenza in questa istanza di un oggetto DependencyObject.

(Ereditato da DependencyObject)
InterpolateValue(Int16, Double)

Restituisce il valore interpolato di un fotogramma chiave specifico in corrispondenza dell'incremento dello stato specificato.

(Ereditato da Int16KeyFrame)
InterpolateValueCore(Int16, Double)

Usa l'interpolazione discreta per eseguire la transizione tra il valore del fotogramma chiave precedente e il valore del fotogramma chiave corrente.

InvalidateProperty(DependencyProperty)

Rivaluta il valore effettivo per la proprietà di dipendenza specificata.

(Ereditato da DependencyObject)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
OnChanged()

Chiamato quando l'oggetto corrente Freezable viene modificato.

(Ereditato da Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject, DependencyProperty)

Questo membro supporta l'infrastruttura di Windows Presentation Foundation (WPF) e non deve essere usato direttamente dal codice.

(Ereditato da Freezable)
OnFreezablePropertyChanged(DependencyObject, DependencyObject)

Assicura che vengano stabiliti puntatori di contesto appropriati per un DependencyObjectType membro dati appena impostato.

(Ereditato da Freezable)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

Esegue l'override dell'implementazione DependencyObject di OnPropertyChanged(DependencyPropertyChangedEventArgs) per richiamare anche i Changed gestori in risposta a una proprietà di dipendenza modificata di tipo Freezable.

(Ereditato da Freezable)
ReadLocalValue(DependencyProperty)

Restituisce il valore locale di una proprietà di dipendenza, se esistente.

(Ereditato da DependencyObject)
ReadPreamble()

Assicura che l'oggetto Freezable sia accessibile da un thread valido. Gli eredi di Freezable devono chiamare questo metodo all'inizio di qualsiasi API che legge i membri dati che non sono proprietà di dipendenza.

(Ereditato da Freezable)
SetCurrentValue(DependencyProperty, Object)

Imposta il valore di una proprietà di dipendenza senza modificarne l'origine del valore.

(Ereditato da DependencyObject)
SetValue(DependencyProperty, Object)

Imposta il valore locale di una proprietà di dipendenza, specificato dall'identificatore della proprietà di dipendenza.

(Ereditato da DependencyObject)
SetValue(DependencyPropertyKey, Object)

Imposta il valore locale di una proprietà di dipendenza di sola lettura, specificato dall'identificatore DependencyPropertyKey della proprietà di dipendenza.

(Ereditato da DependencyObject)
ShouldSerializeProperty(DependencyProperty)

Restituisce un valore che indica se i processi di serializzazione devono serializzare il valore per la proprietà di dipendenza specificata.

(Ereditato da DependencyObject)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)
VerifyAccess()

Impone che il thread chiamante abbia accesso a questo DispatcherObjectoggetto .

(Ereditato da DispatcherObject)
WritePostscript()

Genera l'evento Changed per Freezable e richiama il relativo OnChanged() metodo. Le classi che derivano da Freezable devono chiamare questo metodo alla fine di qualsiasi API che modifica i membri della classe non archiviati come proprietà di dipendenza.

(Ereditato da Freezable)
WritePreamble()

Verifica che l'oggetto Freezable non sia bloccato e che sia accessibile da un contesto di threading valido. Freezable Gli eredi devono chiamare questo metodo all'inizio di qualsiasi API che scrive nei membri dati che non sono proprietà di dipendenza.

(Ereditato da Freezable)

Eventi

Nome Descrizione
Changed

Si verifica quando l'oggetto Freezable o un oggetto che contiene viene modificato.

(Ereditato da Freezable)

Implementazioni dell'interfaccia esplicita

Nome Descrizione
IKeyFrame.Value

Ottiene o imposta il valore associato a un'istanza KeyTime di .

(Ereditato da Int16KeyFrame)

Si applica a

Vedi anche