Timeline.CurrentGlobalSpeedInvalidated Timeline.CurrentGlobalSpeedInvalidated Timeline.CurrentGlobalSpeedInvalidated Timeline.CurrentGlobalSpeedInvalidated Event

定義

發生於時刻表時鐘的時間進行速率變更時。Occurs when the rate at which time progresses for the timeline's clock changes.

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

範例

下列範例顯示如何註冊CurrentGlobalSpeedInvalidated事件。The following example shows how to register for the CurrentGlobalSpeedInvalidated event.

/*

   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

備註

在下列情況下, 時間軸時鐘的目前全球速度會改變:The current global speed of a timeline's clock changes in the following circumstances:

  • 時鐘會因為其時間軸的AutoReverse設定而變更方向。The clock changes direction because of its timeline's AutoReverse setting.

  • 時鐘的速度會加速或減速, 因為它AccelerationRatioDecelerationRatio時間軸或屬性設定。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.

  • CurrentGlobalSpeed其中一個時鐘父系變更的。The CurrentGlobalSpeed of one of the clock's parent changes.

事件可用於追蹤時間軸的時鐘何時暫停; 在事件處理常式中, 請使用腳本的GetCurrentGlobalSpeed方法或檢查時鐘的IsPaused屬性, 以判斷其時鐘是否已暫停; 比較此專案與CurrentGlobalSpeedInvalidated先前快取的值, 用來判斷是否已變更。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.

事件處理常式的Object參數Clock是時間軸的。 EventHandlerThe Object parameter of the EventHandler event handler is the timeline's Clock.

雖然這個事件處理常式似乎與時間軸相關聯, 但它實際上會向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.

適用於

另請參閱