Timeline.CurrentGlobalSpeedInvalidated Événement

Définition

Se produit lorsque le taux auquel l'heure progresse pour l'horloge de la chronologie change.

C#
public event EventHandler CurrentGlobalSpeedInvalidated;

Type d'événement

Exemples

L’exemple suivant montre comment s’inscrire à l’événement CurrentGlobalSpeedInvalidated .

C#
/*

   This example shows how to register for the
   CurrentGlobalSpeedInvalidated event
   using a Timeline. 

*/

using System;
using System.Windows;
using System.Windows.Navigation;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls;
using System.Windows.Input;

namespace Microsoft.Samples.Animation.TimingBehaviors
{

    public class TimelineCurrentGlobalSpeedInvalidatedExample : Page {

        private TextBlock currentTimeTextBlock;
        public TimelineCurrentGlobalSpeedInvalidatedExample()
        {
            
            // Create a name scope.
            NameScope.SetNameScope(this, new NameScope());
            
            WindowTitle = "GetAnimationBaseValue Example";
            StackPanel myPanel = new StackPanel();
            myPanel.Margin = new Thickness(20);     
            
            // Create a rectangle.
            Rectangle animatedRectangle = new Rectangle();
            animatedRectangle.Width = 100;
            animatedRectangle.Height = 50;
            animatedRectangle.Margin = new Thickness(50);
            animatedRectangle.Fill = Brushes.Orange;
            animatedRectangle.Stroke = Brushes.Gray;
            animatedRectangle.StrokeThickness = 2;
            
            // Create a RotateTransform.
            RotateTransform animatedTransform = new RotateTransform();
            animatedTransform.Angle = 0;
            this.RegisterName("animatedTransform", animatedTransform);
            animatedRectangle.RenderTransform = animatedTransform;
            animatedRectangle.RenderTransformOrigin = new Point(0.5,0.5);
            myPanel.Children.Add(animatedRectangle);
            this.Content = myPanel;

            // Create a TextBlock to show the storyboard's current time.
            currentTimeTextBlock = new TextBlock();
            myPanel.Children.Add(currentTimeTextBlock);
            
            // Animate the RotateTransform's angle using a Storyboard.
            DoubleAnimation angleAnimation = new DoubleAnimation(0,360, TimeSpan.FromSeconds(5));
            angleAnimation.RepeatBehavior = RepeatBehavior.Forever;
            angleAnimation.AutoReverse = true;
            Storyboard.SetTargetName(angleAnimation, "animatedTransform");
            Storyboard.SetTargetProperty(angleAnimation, 
                new PropertyPath(RotateTransform.AngleProperty));
  
            Storyboard theStoryboard = new Storyboard();
            theStoryboard.Children.Add(angleAnimation);            
            
            // Register the CurrentGlobalSpeedInvalidated event.
            // You must register for events before you begin 
            // the storyboard.
            angleAnimation.CurrentGlobalSpeedInvalidated += 
                new EventHandler(angleAnimation_CurrentGlobalSpeedInvalidated);
            
            // Start the storyboard.
            theStoryboard.Begin(animatedRectangle, true);
        }
        
        private void angleAnimation_CurrentGlobalSpeedInvalidated(object sender, EventArgs e)
        {
            
            // Sender is the clock that was created for the DoubleAnimation.
            Clock doubleAnimationClock = (Clock)sender;
            
            // Update the TextBlock with the time of its parent.
            currentTimeTextBlock.Text = doubleAnimationClock.Parent.CurrentTime.ToString();       
        }
    }
}

Remarques

La vitesse globale actuelle de l’horloge d’un chronologie change dans les circonstances suivantes :

  • L’horloge change de direction en raison du paramètre de AutoReverse son chronologie.

  • L’horloge accélère ou ralentit en raison de ses paramètres de chronologie ou DecelerationRatio de AccelerationRatio propriété.

  • L’horloge est suspendue ou reprise.

  • L’horloge devient inactive ou se réactive.

  • de CurrentGlobalSpeed l’un des changements parents de l’horloge.

L’événement CurrentGlobalSpeedInvalidated est utile pour suivre quand l’horloge d’un chronologie est en pause ; dans votre gestionnaire d’événements, utilisez la méthode de GetCurrentGlobalSpeed votre storyboard ou case activée la propriété de IsPaused l’horloge pour déterminer si son horloge est suspendue; comparez-la à une valeur précédemment mise en cache pour déterminer si elle a changé.

Le Object paramètre du EventHandler gestionnaire d’événements est le chronologie Clock.

Bien que ce gestionnaire d’événements semble être associé à un chronologie, il s’inscrit en fait avec le Clock créé pour cette chronologie. Pour plus d’informations, consultez Vue d’ensemble des événements de minutage.

S’applique à

Produit Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Voir aussi