Skip to main content
.NET Framework Class Library
AnimationClock Class

Maintains the run-time state of an AnimationTimeline and processes its output values.

Namespace:   System.Windows.Media.Animation
Assembly:  PresentationCore (in PresentationCore.dll)
Syntax
Public Class AnimationClock _
	Inherits [%$TOPIC/ms618394_en-us_VS_110_3_0_0_0_0%]
public class AnimationClock : [%$TOPIC/ms618394_en-us_VS_110_3_0_1_0_0%]
public ref class AnimationClock : public [%$TOPIC/ms618394_en-us_VS_110_3_0_2_0_0%]
type AnimationClock =  
    class 
        inherit [%$TOPIC/ms618394_en-us_VS_110_3_0_3_0_0%] 
    end

The AnimationClock type exposes the following members.

Constructors
  NameDescription
Protected method AnimationClock Initializes a new instance of the AnimationClock class.
Top
Properties
  NameDescription
Public property ControllerGets a ClockController that can be used to start, pause, resume, seek, skip, stop, or remove this Clock. (Inherited from Clock.)
Public property CurrentGlobalSpeedGets the rate at which the clock's time is currently progressing, compared to real-world time. (Inherited from Clock.)
Protected property CurrentGlobalTimeGets the current global time, as established by the WPF timing system.  (Inherited from Clock.)
Public property CurrentIterationGet the current iteration of this clock. (Inherited from Clock.)
Public property CurrentProgressGets the current progress of this Clock within its current iteration. (Inherited from Clock.)
Public property CurrentStateGets a value indicating whether the clock is currently Active, Filling, or Stopped. (Inherited from Clock.)
Public property CurrentTimeGets this clock's current time within its current iteration. (Inherited from Clock.)
Public property DispatcherGets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)
Public property HasControllableRootGets a value that indicates whether this Clock is part of a controllable clock tree. (Inherited from Clock.)
Public property IsPausedGets a value that indicates whether this Clock, or any of its parents, is paused. (Inherited from Clock.)
Public property NaturalDurationGets the natural duration of this clock's Timeline. (Inherited from Clock.)
Public property ParentGets the clock that is the parent of this clock. (Inherited from Clock.)
Public property TimelineGets the AnimationTimeline that describes this clock's behavior.
Top
Methods
  NameDescription
Public method CheckAccessDetermines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Protected method DiscontinuousTimeMovementWhen implemented in a derived class, will be invoked whenever a clock repeats, skips, or seeks. (Inherited from Clock.)
Public method Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Protected method GetCanSlipReturns whether the Clock has its own external time source, which may require synchronization with the timing system. (Inherited from Clock.)
Protected method GetCurrentTimeCoreGets this clock's current time within its current iteration. (Inherited from Clock.)
Public method GetCurrentValueGets the current output value of the AnimationClock.
Public method GetHashCodeServes as the default hash function. (Inherited from Object.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected method SpeedChangedWhen implemented in a derived class, will be invoked whenever a clock begins, skips, pauses, resumes, or when the clock's SpeedRatio is modified. (Inherited from Clock.)
Protected method StoppedWhen implemented in a derived class, will be invoked whenever a clock is stopped using the Stop method. (Inherited from Clock.)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Public method VerifyAccessEnforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject.)
Top
Events
  NameDescription
Public event CompletedOccurs when this clock has completely finished playing. (Inherited from Clock.)
Public event CurrentGlobalSpeedInvalidatedOccurs when the clock's speed is updated. (Inherited from Clock.)
Public event CurrentStateInvalidatedOccurs when the clock's CurrentState property is updated. (Inherited from Clock.)
Public event CurrentTimeInvalidatedOccurs when this clock's CurrentTime becomes invalid. (Inherited from Clock.)
Public event RemoveRequestedOccurs when the Remove method is called on this Clock or one of its parent clocks. (Inherited from Clock.)
Top
Remarks

AnimationClock objects are generated from AnimationTimeline objects. An AnimationTimeline describes an animation's output values, duration, begin time, end time, and other fundamental animation information. An AnimationClock processes the animation values described by an AnimationTimeline object.

Examples

This example shows how to use Clock objects to animate a property.

There are three ways to animate a dependency property:

Storyboard objects and the BeginAnimation method enable you to animate properties without directly creating and distributing clocks (for examples, see How to: Animate a Property by Using a Storyboard and How to: Animate a Property Without Using a Storyboard); clocks are created and distributed for you automatically.

The following example shows how to create an AnimationClock and apply it to two similar properties.

'
'    This example shows how to create and apply
'    an AnimationClock.
'


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


Namespace Microsoft.Samples.Animation.TimingBehaviors
	Public Class AnimationClockExample
		Inherits Page

		Private myScaleTransform As ScaleTransform

		Public Sub New()

			Me.WindowTitle = "Opacity Animation Example"
			Me.Background = Brushes.White
			Dim myStackPanel As New StackPanel()
			myStackPanel.Margin = New Thickness(20)

			' Create a button that with a ScaleTransform.
			' The ScaleTransform will animate when the
			' button is clicked.
			Dim myButton As New Button()
			myButton.Margin = New Thickness(50)
			myButton.HorizontalAlignment = HorizontalAlignment.Left
			myButton.Content = "Click Me"
			myScaleTransform = New ScaleTransform(1,1)
			myButton.RenderTransform = myScaleTransform


			' Associate an event handler with the
			' button's Click event.
			AddHandler myButton.Click, AddressOf myButton_Clicked

			myStackPanel.Children.Add(myButton)
			Me.Content = myStackPanel
		End Sub

		' Create and apply and animation when the button is clicked.
		Private Sub myButton_Clicked(ByVal sender As Object, ByVal e As RoutedEventArgs)

			' Create a DoubleAnimation to animate the
			' ScaleTransform.
			Dim myAnimation As New DoubleAnimation(1, 5, New Duration(TimeSpan.FromSeconds(5))) ' "To" value -  "From" value
			myAnimation.AutoReverse = True

			' Create a clock the for the animation.
			Dim myClock As AnimationClock = myAnimation.CreateClock()

			' Associate the clock the ScaleX and
			' ScaleY properties of the button's
			' ScaleTransform.
			myScaleTransform.ApplyAnimationClock(ScaleTransform.ScaleXProperty, myClock)
			myScaleTransform.ApplyAnimationClock(ScaleTransform.ScaleYProperty, myClock)
		End Sub
	End Class
End Namespace
/*
    This example shows how to create and apply
    an AnimationClock.
*/ 

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


namespace Microsoft.Samples.Animation.TimingBehaviors
{
    public class AnimationClockExample : Page
    {

        ScaleTransform myScaleTransform;

        public AnimationClockExample()
        {

            this.WindowTitle = "Opacity Animation Example";
            this.Background = Brushes.White;
            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Margin = new Thickness(20);

            // Create a button that with a ScaleTransform. 
            // The ScaleTransform will animate when the 
            // button is clicked.
            Button myButton = new Button();
            myButton.Margin = new Thickness(50);
            myButton.HorizontalAlignment = HorizontalAlignment.Left;
            myButton.Content = "Click Me";           
            myScaleTransform = new ScaleTransform(1,1);
            myButton.RenderTransform = myScaleTransform;


            // Associate an event handler with the 
            // button's Click event.
            myButton.Click += new RoutedEventHandler(myButton_Clicked);

            myStackPanel.Children.Add(myButton);
            this.Content = myStackPanel;
        }

        // Create and apply and animation when the button is clicked. 
        private void myButton_Clicked(object sender, RoutedEventArgs e)
        {

            // Create a DoubleAnimation to animate the 
            // ScaleTransform.
            DoubleAnimation myAnimation = 
                new DoubleAnimation(
                    1, // "From" value
                    5, // "To" value  
                    new Duration(TimeSpan.FromSeconds(5))
                );
            myAnimation.AutoReverse = true;

            // Create a clock the for the animation.
            AnimationClock myClock = myAnimation.CreateClock();            

            // Associate the clock the ScaleX and 
            // ScaleY properties of the button's 
            // ScaleTransform.
            myScaleTransform.ApplyAnimationClock(
                ScaleTransform.ScaleXProperty, myClock);
            myScaleTransform.ApplyAnimationClock(
                ScaleTransform.ScaleYProperty, myClock);
        }
    }
}

For an example showing how to interactively control a Clock after it starts, see How to: Interactively Control a Clock.

Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.