--- title: "Timing Behaviors Overview" ms.date: "03/30/2017" helpviewer_keywords: - "timing behaviors [WPF]" - "behaviors [WPF], timing" ms.assetid: 5b714d46-bd46-48b8-b467-b4be89ba3091 --- # Timing Behaviors Overview This topic describes the timing behaviors of animations and other objects. ## Prerequisites To understand this topic, you should be familiar with basic animation features. For more information, see the [Animation Overview](animation-overview.md). ## Timeline Types A represents a segment of time. It provides properties that enable you to specify the length of that segment, when it should start, how many times it will repeat, how fast time progresses in that segment, and more. Classes that inherit from the timeline class provide additional functionality, such as animation and media playback. [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)] provides the following types. |Timeline type|Description| |-------------------|-----------------| ||Abstract base class for objects that generate output values for animating properties.| ||Generates output from a media file.| ||A type of that groups and controls child objects.| ||A type of that provides targeting information for the Timeline objects it contains.| ||Abstract base class that defines timing behaviors.| ||Abstract class for objects that can contain other objects.| ## Properties that Control the Length of a Timeline A represents a segment of time, and the length of a timeline can be described in different ways. The following table defines several terms for describing the length of a timeline. |Term|Description|Properties|||| |----------|-----------------|----------------|-|-|-| |Simple duration|The length of time a timeline takes to make a single forward iteration.||||| |One repetition|The length of time it takes for a timeline to play forward once and, if the property is true, play backwards once.|, |||| |Active period|The length of time it takes for a timeline to complete all the repetitions specified by its property.|, , |||| ### The Duration Property As previously mentioned, a timeline represents a segment of time. The length of that segment is determined by the timeline's . When a timeline reaches the end of its duration, it stops playing. If the timeline has child timelines, they stop playing as well. In the case of an animation, the specifies how long the animation takes to transition from its starting value to its ending value. A timeline's duration is sometimes called its *simple duration*, to distinguish between the duration of a single iteration and the total length of time the animation plays including repetitions. You can specify a duration using a finite time value or the special values or . An animation's duration should resolve to a value, so it can transition between values. The following example shows a with a of five seconds. [!code-xaml[animation_ovws_snippet#AnimationWith5SecondDurationInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#animationwith5seconddurationinline)] Container timelines, such as and , have a default duration of , which means they automatically end when their last child stops playing. The following example shows a whose resolves to five seconds, the length of time it takes all its child objects to complete. [!code-xaml[animation_ovws_snippet#ContainerTimelineExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#containertimelineexampleinline)] By setting the of a container timeline to a value, you can force to play longer or shorter than its child objects would play. If you set the to a value that's smaller than the length of the container timeline's child objects, the child objects stop playing when the container timeline does. The following example sets the of the from the preceding examples to three seconds. As a result, the first stops progressing after three seconds, when it has animated the target rectangle's width to 60. [!code-xaml[animation_ovws_snippet#ContainerTimelineWithShorterDurationExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#containertimelinewithshorterdurationexampleinline)] ### The RepeatBehavior Property The property of a controls how many times it repeats its simple duration. Using the property, you can specify how many times the timeline plays (an iteration ) or the total length of time it should play (a repeat ). In either case, the animation goes through as many beginning-to-end runs as necessary to fill the requested count or duration. By default, timelines have an iteration count of `1.0`, which means they play once and do not repeat at all. The following example uses the property to make a play for twice its simple duration by specifying an iteration count. [!code-xaml[animation_ovws_snippet#TBRepeatBehavior2xExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#tbrepeatbehavior2xexampleinline)] The next example uses the property to make the play for half its simple duration. [!code-xaml[animation_ovws_snippet#TBRepeatBehavior05xExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#tbrepeatbehavior05xexampleinline)] If you set the property of a to , the repeats until stopped interactively or by the timing system. The following example uses the property to make the play indefinitely. [!code-xaml[animation_ovws_snippet#TBRepeatBehaviorForeverExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#tbrepeatbehaviorforeverexampleinline)] For an additional example, see [Repeat an Animation](how-to-repeat-an-animation.md). ### The AutoReverse Property The property specifies whether a will play backwards at the end of each forward iteration. The following example sets to the property of a to `true`; as a result, it animates from zero to 100, and then from 100 to zero. It plays for a total of 10 seconds. [!code-xaml[animation_ovws_snippet#TBAutoReverseExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#tbautoreverseexampleinline)] When you use a value to specify the of a and the property of that is `true`, a single repetition consists of one forward iteration followed by one backwards iteration. The following example sets the of the from the preceding example to a of two. As a result, the plays for 20 seconds: forward for five seconds, backwards for five seconds, forward for 5 seconds again, and then backwards for five seconds. [!code-xaml[animation_ovws_snippet#TBAutoReverseRepeatExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#tbautoreverserepeatexampleinline)] If a container timeline has child objects, they reverse when the container timeline does. For additional examples, see [Specify Whether a Timeline Automatically Reverses](how-to-specify-whether-a-timeline-automatically-reverses.md). ## The BeginTime Property The property enables you to specify when a timeline starts. A timeline's begin time is relative to its parent timeline. A begin time of zero seconds means the timeline starts as soon as it parent starts; any other value creates an offset between when the parent timeline starts playing and when the child timeline plays. For example, a begin time of two seconds means the timeline starts playing when its parent has reached a time of two seconds. By default, all timelines have a begin time of zero seconds. You may also set a timeline's begin time to `null`, which prevents the timeline from starting. In [!INCLUDE[TLA2#tla_winclient](../../../includes/tla2sharptla-winclient-md.md)], you specify null using the [x:Null Markup Extension](/dotnet/desktop/xaml-services/xnull-markup-extension). Note that the begin time is not applied each time a timeline repeats because of its setting. If you were to create an animation with a of 10 seconds and a of , there would be a 10-second delay before the animation played for the first time, but not for each successive repetition. However, if the animation's parent timeline were to restart or repeat, the 10-second delay would occur. The property is useful for staggering timelines. The following example creates a that has two child objects. The first animation has a of five seconds, and the second has a of 3 seconds. The example sets the of the second to 5 seconds, so that it begins playing after the first ends. [!code-xaml[animation_ovws_snippet#TBBeginTimeExampleInline](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#tbbegintimeexampleinline)] ## The FillBehavior Property When a reaches the end of its total active duration, the property specifies whether it stops or holds its last value. An animation with a of "holds" its output value: the property being animated retains the last value of the animation. A value of causes that the animation stop affecting its target property after it ends. The following example creates a that has two child objects. Both objects animate the of a from 0 to 100. The elements have non-animated values of 500 [device independent pixels]. - The property of the first is set to , the default value. As a result, the Width of the Rectangle stays at 100 after the ends. - The property of the second is set to . As a result, the of the second reverts to 500 after the ends. [!code-xaml[animation_ovws_snippet#TBFillBehaviorExample](~/samples/snippets/csharp/VS_Snippets_Wpf/animation_ovws_snippet/CS/TimingBehaviorsExample1.xaml#tbfillbehaviorexample)] ## Properties that Control the Speed of a Timeline The class provides three properties for specifying its speed: - – Specifies that rate, relative to its parent, at which time progresses for a . Values greater than one increase the speed of the and its child objects; values between zero and one slow it down. A value of one indicates that progresses at the same rate as its parent. The setting of a container timeline affects all of its child objects as well. - – Specifies the percentage of the of a Timeline spent accelerating. For an example, see [How to: Accelerate or Decelerate an Animation](how-to-accelerate-or-decelerate-an-animation.md). - - Specifies the percentage of the of a Timeline spent decelerating. For an example, see [How to: Accelerate or Decelerate an Animation](how-to-accelerate-or-decelerate-an-animation.md). ## See also - [Animation Overview](animation-overview.md) - [Animation and Timing System Overview](animation-and-timing-system-overview.md) - [Timing Events Overview](timing-events-overview.md) - [How-to Topics](animation-and-timing-how-to-topics.md) - [Animation Timing Behavior Sample](https://github.com/Microsoft/WPF-Samples/tree/master/Animation/AnimationTiming)