Ce sujet n'a pas encore été évalué - Évaluez ce sujet

DiscreteRectKeyFrame, classe

Mise à jour : novembre 2007

Passe de Rect la valeur correspondant à la précédente image clé à sa propre valeur Value en utilisant une opération d'interpolation discrète.

Espace de noms :  System.Windows.Media.Animation
Assembly :  PresentationCore (dans PresentationCore.dll)
XMLNS pour XAML : http://schemas.microsoft.com/winfx/xaml/presentation

public class DiscreteRectKeyFrame : RectKeyFrame
public class DiscreteRectKeyFrame extends RectKeyFrame
public class DiscreteRectKeyFrame extends RectKeyFrame
<DiscreteRectKeyFrame .../>

Cette classe est utilisée dans le cadre de la collection RectKeyFrameCollection avec un RectAnimationUsingKeyFrames afin d'animer une valeur de la propriété Rect en fonction d'un ensemble d'images clés.

Une image clé définit un segment du RectAnimationUsingKeyFrames auquel elle appartient. Une valeur Value cible et une période de clé KeyTime sont définies pour chaque image clé. Le KeyTime indique l'heure à laquelle la valeur Value de l'image clé doit être atteinte. Une image clé passe de la valeur cible de l'image clé précédente à sa propre valeur cible. Elle démarre à la fin de l'image clé précédente et s'achève au terme de sa propre période de clé.

Les images clés discrètes telles que DiscreteRectKeyFrame créent des « sauts » soudains entre les valeurs (aucune interpolation). En d'autres termes, la valeur de la propriété animée reste inchangée tant que la période de clé de l'image clé n'a pas atteint sa valeur. Ce délai échu, la propriété animée passe alors soudainement à la valeur cible.

Cet exemple indique comment animer la propriété Rect d'un RectangleGeometry à l'aide d'images clés.

L'exemple suivant utilise la classe RectAnimationUsingKeyFrames pour animer la propriété Rect d'un RectangleGeometry. Cette animation utilise trois images clés de la manière suivante :

  1. Pendant les deux premières secondes, utilise une instance de la classe LinearRectKeyFrame pour animer une modification graduelle de la position, de la largeur et de la hauteur d'un rectangle. Les images clés linéaires telles que LinearRectKeyFrame créent une transition linéaire fluide entre les valeurs.

  2. À la fin de la demi-seconde suivante, utilise une instance de la classe DiscreteRectKeyFrame pour diminuer soudainement la hauteur du rectangle. Les images clés discrètes telles que DiscreteRectKeyFrame créent des modifications soudaines entre les valeurs, c'est-à-dire que la diminution de la hauteur se produit rapidement et n'est pas subtile.

  3. Durant les deux dernières secondes, utilise une instance de la classe SplineRectKeyFrame pour rétablir la taille et la position de départ du rectangle. Des images clé spline telles que SplineRectKeyFrame créent une transition variable entre des valeurs en fonction des valeurs de la propriété KeySpline. Dans cet exemple, la modification commence lentement et accélère de façon exponentielle vers la fin du segment temporel.

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 RectAnimationUsingKeyFrames class to
    /// animate the position and size of a rectangle.
    /// Key frame animations enable you to create complex animations 
    /// by specifying multiple destination values
    /// and controlling the animation's interpolation method.
    /// </summary>
    public class RectAnimationUsingKeyFramesExample : Page
    {
        public RectAnimationUsingKeyFramesExample()
        {
            Title = "RectAnimationUsingKeyFrames 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());

            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Orientation = Orientation.Vertical;
            myStackPanel.HorizontalAlignment = HorizontalAlignment.Center;

            //Add the Path Element
            Path myPath = new Path();
            myPath.Stroke = Brushes.Black;
            myPath.Fill = Brushes.LemonChiffon;
            myPath.StrokeThickness = 1;

            // Create a RectangleGeometry to specify the Path data.
            RectangleGeometry myRectangleGeometry = new RectangleGeometry();
            myRectangleGeometry.Rect = new Rect(0, 200, 100, 100);
            myPath.Data = myRectangleGeometry;

            myStackPanel.Children.Add(myPath);

            // Assign the TranslateTransform a name so that
            // it can be targeted by a Storyboard.
            this.RegisterName(
                "AnimatedRectangleGeometry", myRectangleGeometry);

            // Create a RectAnimationUsingKeyFrames to
            // animate the RectangleGeometry.
            RectAnimationUsingKeyFrames rectAnimation 
                = new RectAnimationUsingKeyFrames();
            rectAnimation.Duration = TimeSpan.FromSeconds(6);

            // Set the animation to repeat forever. 
            rectAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Animate position, width, and height in first 2 seconds. LinearRectKeyFrame creates
            // a smooth, linear animation between values.
            rectAnimation.KeyFrames.Add(
                new LinearRectKeyFrame(
                    new Rect(600,50,200,50), // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))) // KeyTime
                );

            // In the next half second, change height to 10. DiscreteRectKeyFrame creates a 
            // sudden "jump" between values.
            rectAnimation.KeyFrames.Add(
                new DiscreteRectKeyFrame(
                    new Rect(600, 50, 200, 10), // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2.5))) // KeyTime
                );

            // In the final 2 seconds of the animation, go back to the starting position, width, and height.  
            // Spline key frames like SplineRectKeyFrame creates a variable transition between values depending 
            // on the KeySpline property. In this example, the animation starts off slow but toward the end of 
            // the time segment, it speeds up exponentially.
            rectAnimation.KeyFrames.Add(
                new SplineRectKeyFrame(
                    new Rect(0, 200, 100, 100), // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(4.5)), // KeyTime
                    new KeySpline(0.6, 0.0, 0.9, 0.0) // KeySpline
                    )
                );

            // Set the animation to target the Rect property
            // of the object named "AnimatedRectangleGeometry."
            Storyboard.SetTargetName(rectAnimation, "AnimatedRectangleGeometry");
            Storyboard.SetTargetProperty(
                rectAnimation, new PropertyPath(RectangleGeometry.RectProperty));

            // Create a storyboard to apply the animation.
            Storyboard rectStoryboard = new Storyboard();
            rectStoryboard.Children.Add(rectAnimation);

            // Start the storyboard after the rectangle loads.
            myPath.Loaded += delegate(object sender, RoutedEventArgs e)
            {
                rectStoryboard.Begin(this);
            };

            Content = myStackPanel;
        }

    }
}


<Page  
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="ThicknessAnimationUsingKeyFrames Example">

  <StackPanel Orientation="Vertical" HorizontalAlignment="Center">

    <Path Stroke="Black" StrokeThickness="1" Fill="LemonChiffon">
      <Path.Data>
        <RectangleGeometry x:Name="myRectangleGeometry" Rect="0,200,100,100" />
      </Path.Data>
      <Path.Triggers>
        <EventTrigger RoutedEvent="Path.Loaded">
          <BeginStoryboard>
            <Storyboard>

              <!-- Animate the Rect property of the RectangleGeometry which causes the
              rectangle to animate its position as well as its width and height. -->
              <RectAnimationUsingKeyFrames
                Storyboard.TargetName="myRectangleGeometry"
                Storyboard.TargetProperty ="Rect"
                Duration="0:0:6" FillBehavior="HoldEnd" RepeatBehavior="Forever">

                <!-- Animate position, width, and height in first 2 seconds. LinearRectKeyFrame creates
                a smooth, linear animation between values. -->
                <LinearRectKeyFrame Value="600,50,200,50" KeyTime="0:0:2" />

                <!-- In the next half second, change height to 10. DiscreteRectKeyFrame creates a 
                sudden "jump" between values. -->
                <DiscreteRectKeyFrame Value="600,50,200,10" KeyTime="0:0:2.5" />

                <!-- In the final 2 seconds of the animation, go back to the starting position, width, and height.  
                Spline key frames like SplineRectKeyFrame creates a variable transition between values depending 
                on the KeySpline property. In this example, the animation starts off slow but toward the end of 
                the time segment, it speeds up exponentially.-->
                <SplineRectKeyFrame Value="0,200,100,100" KeyTime="0:0:4.5" KeySpline="0.6,0.0 0.9,0.00"  />
              </RectAnimationUsingKeyFrames>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Path.Triggers>
    </Path>

  </StackPanel>
</Page>


Pour l'exemple complet, consultez Animation d'image clé, exemple.

Tous les membres static (Shared en Visual Basic) publics de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Windows Vista

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0
Cela vous a-t-il été utile ?
(1500 caractères restants)

Ajouts de la communauté

AJOUTER
© 2013 Microsoft. Tous droits réservés.