Export (0) Print
Expand All

Animatable.ApplyAnimationClock Method (DependencyProperty, AnimationClock)

Applies an AnimationClock to the specified DependencyProperty. If the property is already animated, the SnapshotAndReplace handoff behavior is used.

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

public void ApplyAnimationClock (
	DependencyProperty dp,
	AnimationClock clock
)
public final void ApplyAnimationClock (
	DependencyProperty dp, 
	AnimationClock clock
)
public final function ApplyAnimationClock (
	dp : DependencyProperty, 
	clock : AnimationClock
)
You cannot use methods in XAML.

Parameters

dp

The property to animate.

clock

The clock with which to animate the specified property. If clock is a null reference (Nothing in Visual Basic), all animations will be removed from the specified property (but not stopped).

Note that using this method to removing clocks from a property does not stop those clocks.

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

There are three ways to animate a dependency property:

  • Create an AnimationTimeline and associate it with that property by using a Storyboard.

  • Use the object's BeginAnimation method to apply a single AnimationTimeline to a target property.

  • Create a Clock from an AnimationTimeline and apply it to a property.

Storyboard objects and the BeginAnimation method enable you to animate properties without directly creating and distributing clocks (see Animate a Property and Apply a Local (Non-Storyboard) Animation to a Property for examples); 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.
*/

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.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft