Timeline.CurrentGlobalSpeedInvalidated Event

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Occurs when the rate at which time progresses for the timeline's clock changes.

Namespace:   System.Windows.Media.Animation
Assembly:  PresentationCore (in PresentationCore.dll)

Public Event CurrentGlobalSpeedInvalidated As EventHandler

The current global speed of a timeline's clock changes in the following circumstances:

  • The clock changes direction because of its timeline's AutoReverse setting.

  • The clock accelerates or decelerates because of its timeline's AccelerationRatio or DecelerationRatio property settings.

  • The clock is paused or resumed.

  • The clock becomes inactive or reactivates.

  • The CurrentGlobalSpeed of one of the clock's parent changes.

The CurrentGlobalSpeedInvalidated event is useful for tracking when a timeline's clock becomes paused; in your event handler, use your storyboard's GetCurrentGlobalSpeed method or check the clock's IsPaused property to determine whether its clock is paused; compare this against a previously cached value to determine whether it changed.

The Object parameter of the EventHandler event handler is the timeline's Clock.

Although this event handler appears to be associated with a timeline, it actually registers with the Clock created for this timeline. For more information, see the Timing Events Overview.

The following example shows how to register for the CurrentGlobalSpeedInvalidated event.

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

Imports System
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

.NET Framework
Available since 3.0
Return to top
Show: