---
title: "Property Animation Techniques Overview"
ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
- "cpp"
helpviewer_keywords:
- "animation [WPF], properties [WPF], methods for"
- "properties [WPF], methods for animating"
ms.assetid: 74f61413-f8c0-4e75-bf04-951886426c8b
---
# Property Animation Techniques Overview
This topic describes the different approaches for animating properties: storyboards, local animations, clocks, and per-frame animations.
## Prerequisites
To understand this topic, you should be familiar with the basic animation features described in the [Animation Overview](animation-overview.md).
## Different Ways to Animate
Because there are many different scenarios for animating properties, [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides several approaches for animating properties.
For each approach, the following table indicates whether it can be used per-instance, in styles, in control templates, or in data templates; whether it can be used in [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)]; and whether the approach enables you to interactively control the animation. "Per-Instance" refers to the technique of applying an animation or storyboard directly to instances of an object, rather than in a style, control template, or data template.
|Animation technique|Scenarios|Supports XAML|Interactively controllable|
|-------------------------|---------------|-------------------|--------------------------------|
|Storyboard animation|Per-instance, , , |Yes|Yes|
|Local animation|Per-instance|No|No|
|Clock animation|Per-instance|No|Yes|
|Per-frame animation|Per-instance|No|N/A|
## Storyboard Animations
Use a when you want to define and apply your animations in [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)], interactively control your animations after they start, create a complex tree of animations, or animate in a , or . For an object to be animated by a , it must be a or , or it must be used to set a or . For more details, see the [Storyboards Overview](storyboards-overview.md).
A is a special type of container that provides targeting information for the animations it contains. To animate with a , you complete the following three steps.
1. Declare a and one or more animations.
2. Use the and attached properties to specify the target object and property of each animation.
3. (Code only) Define a for a or . Register the names of the objects to animate with that or .
4. Begin the .
Beginning a applies animations to the properties they animate and starts them. There are two ways to begin a : you can use the method provided by the class, or you can use a action. The only way to animate in [!INCLUDE[TLA2#tla_xaml](../../../includes/tla2sharptla-xaml-md.md)] is to use a action. A action can be used in an , property , or a .
The following table shows the different places where each begin technique is supported: per-instance, style, control template, and data template.
|Storyboard is begun using…|Per-instance|Style|Control template|Data template|Example|
|--------------------------------|-------------------|-----------|----------------------|-------------------|-------------|
| and an |Yes|Yes|Yes|Yes|[Animate a Property by Using a Storyboard](how-to-animate-a-property-by-using-a-storyboard.md)|
| and a property |No|Yes|Yes|Yes|[Trigger an Animation When a Property Value Changes](how-to-trigger-an-animation-when-a-property-value-changes.md)|
| and a |No|Yes|Yes|Yes|[How to: Trigger an Animation When Data Changes](https://docs.microsoft.com/previous-versions/dotnet/netframework-3.5/aa970679(v=vs.90))|
| method|Yes|No|No|No|[Animate a Property by Using a Storyboard](how-to-animate-a-property-by-using-a-storyboard.md)|
For more information about objects, see the [Storyboards Overview](storyboards-overview.md).
## Local Animations
Local animations provide a convenient way to animate a dependency property of any object. Use local animations when you want to apply a single animation to a property and you don't need to interactively control the animation after it starts. Unlike a animation, a local animation can animate an object that isn't associated with a or a . You also don't have to define a for this type of animation.
Local animations may only be used in code, and cannot be defined in styles, control templates, or data templates. A local animation cannot be interactively controlled after it is started.
To animate using a local animation, complete the following steps.
1. Create an object.
2. Use the method of the object that you want to animate to apply the to the property that you specify.
The following example shows how to animate the width and background color of a .
[!code-cpp[animateproperty#11](~/samples/snippets/cpp/VS_Snippets_Wpf/animateproperty/CPP/LocalAnimationExample.cpp#11)]
[!code-csharp[animateproperty#11](~/samples/snippets/csharp/VS_Snippets_Wpf/animateproperty/CSharp/LocalAnimationExample.cs#11)]
[!code-vb[animateproperty#11](~/samples/snippets/visualbasic/VS_Snippets_Wpf/animateproperty/VisualBasic/LocalAnimationExample.vb#11)]
## Clock Animations
Use objects when you want to animate without using a and you want to create complex timing trees or interactively control animations after they start. You can use Clock objects to animate a dependency property of any object.
You cannot use objects directly to animate in styles, control templates, or data templates. (The animation and timing system actually does use objects to animate in styles, control templates, and data templates, but it must create those objects for you from a . For more information about the relationship between objects and objects, see the [Animation and Timing System Overview](animation-and-timing-system-overview.md).)
To apply a single to a property, you complete the following steps.
1. Create an object.
2. Use the method of the to create an .
3. Use the method of the object that you want to animate to apply the to the property you specify.
The following example shows how to create an and apply it to two similar properties.
[!code-csharp[timingbehaviors_procedural_snip#GraphicsMMCreateAnimationClockWholeClass](~/samples/snippets/csharp/VS_Snippets_Wpf/timingbehaviors_procedural_snip/CSharp/AnimationClockExample.cs#graphicsmmcreateanimationclockwholeclass)]
[!code-vb[timingbehaviors_procedural_snip#GraphicsMMCreateAnimationClockWholeClass](~/samples/snippets/visualbasic/VS_Snippets_Wpf/timingbehaviors_procedural_snip/visualbasic/animationclockexample.vb#graphicsmmcreateanimationclockwholeclass)]
To create a timing tree and use it animate properties, you complete the following steps.
1. Use and objects to create the timing tree.
2. Use the of the root to create a .
3. Iterate through the of the and apply its child objects. For each child, use the method of the object that you want to animate to apply the to the property you specify
For more information about Clock objects, see the [Animation and Timing System Overview](animation-and-timing-system-overview.md).
## Per-Frame Animation: Bypass the Animation and Timing System
Use this approach when you need to completely bypass the [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] animation system. One scenario for this approach is physics animations, where each step in the animation requires objects to be recomputed based on the last set of object interactions.
Per-frame animations cannot be defined inside styles, control templates, or data templates.
To animate frame-by-frame, you register for the event of the object that contains the objects you want to animate. This event handler method gets called once per frame. Each time that [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] marshals the persisted rendering data in the visual tree across to the composition tree, your event handler method is called.
In your event handler, perform whatever calculations are necessary for your animation effect and set the properties of the objects you want to animate with these values.
To obtain the presentation time for the current frame, the associated with this event can be cast as , which provide a property that you can use to obtain the current frame's rendering time.
For more information, see the page.
## See also
- [Animation Overview](animation-overview.md)
- [Storyboards Overview](storyboards-overview.md)
- [Animation and Timing System Overview](animation-and-timing-system-overview.md)
- [Dependency Properties Overview](../advanced/dependency-properties-overview.md)