Timeline.CurrentGlobalSpeedInvalidated Evento

Definizione

Si verifica quando cambia la frequenza con cui avanza il tempo per il clock della sequenza temporale.

public:
 event EventHandler ^ CurrentGlobalSpeedInvalidated;
public event EventHandler CurrentGlobalSpeedInvalidated;
member this.CurrentGlobalSpeedInvalidated : EventHandler 
Public Custom Event CurrentGlobalSpeedInvalidated As EventHandler 

Tipo evento

Esempio

Nell'esempio seguente viene illustrato come eseguire la registrazione per l'evento CurrentGlobalSpeedInvalidated .

/*

   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();       
        }
    }
}
'
'
'   This example shows how to register for the
'   CurrentGlobalSpeedInvalidated event
'   using a Timeline. 
'
'

Imports System.Windows
Imports System.Windows.Navigation
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports System.Windows.Controls
Imports System.Windows.Input

Namespace Microsoft.Samples.Animation.TimingBehaviors


    Public Class TimelineCurrentGlobalSpeedInvalidatedExample
        Inherits Page


        Private currentTimeTextBlock As TextBlock
        Public Sub New()

            ' Create a name scope.
            NameScope.SetNameScope(Me, New NameScope())

            WindowTitle = "GetAnimationBaseValue Example"
            Dim myPanel As New StackPanel()
            myPanel.Margin = New Thickness(20)

            ' Create a rectangle.
            Dim animatedRectangle As New Rectangle()
            With animatedRectangle
                .Width = 100
                .Height = 50
                .Margin = New Thickness(50)
                .Fill = Brushes.Orange
                .Stroke = Brushes.Gray
                .StrokeThickness = 2
            End With

            ' Create a RotateTransform.
            Dim animatedTransform As New RotateTransform()
            animatedTransform.Angle = 0
            Me.RegisterName("animatedTransform", animatedTransform)
            animatedRectangle.RenderTransform = animatedTransform
            animatedRectangle.RenderTransformOrigin = New Point(0.5, 0.5)
            myPanel.Children.Add(animatedRectangle)
            Me.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.
            Dim angleAnimation As 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))

            Dim theStoryboard As New Storyboard()
            theStoryboard.Children.Add(angleAnimation)

            ' Register the CurrentGlobalSpeedInvalidated event.
            ' You must register for events before you begin 
            ' the storyboard.
            AddHandler angleAnimation.CurrentGlobalSpeedInvalidated, AddressOf angleAnimation_CurrentGlobalSpeedInvalidated

            ' Start the storyboard.
            theStoryboard.Begin(animatedRectangle, True)

        End Sub

        Private Sub angleAnimation_CurrentGlobalSpeedInvalidated(ByVal sender As Object, ByVal e As EventArgs)

            ' Sender is the clock that was created for the DoubleAnimation.
            Dim doubleAnimationClock As Clock = CType(sender, Clock)

            ' Update the TextBlock with the time of its parent.
            currentTimeTextBlock.Text = doubleAnimationClock.Parent.CurrentTime.ToString()
        End Sub



    End Class

End Namespace

Commenti

La velocità globale corrente dell'orologio di una sequenza temporale cambia nelle circostanze seguenti:

  • L'orologio cambia direzione a causa dell'impostazione della AutoReverse sequenza temporale.

  • L'orologio accelera o decelerate a causa delle impostazioni della AccelerationRatio sequenza temporale o DecelerationRatio delle proprietà.

  • L'orologio viene sospeso o ripreso.

  • L'orologio diventa inattivo o reagisce.

  • L'oggetto CurrentGlobalSpeed di una delle modifiche padre dell'orologio.

L'evento CurrentGlobalSpeedInvalidated è utile per tenere traccia del momento in cui l'orologio di una sequenza temporale viene sospeso; nel gestore eventi usare il metodo dello storyboard GetCurrentGlobalSpeed o controllare la proprietà dell'orologio IsPaused per determinare se il suo orologio è sospeso; confrontarlo con un valore memorizzato nella cache in precedenza per determinare se è stato modificato.

Il Object parametro del EventHandler gestore eventi è il valore della sequenza temporale.Clock

Anche se questo gestore eventi sembra essere associato a una sequenza temporale, viene effettivamente registrato con la Clock sequenza temporale creata per questa sequenza temporale. Per altre informazioni, vedere Panoramica degli eventi di intervallo.

Si applica a

Vedi anche