Files
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

2.2 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
How to: Set a Duration for an Animation 03/30/2017
animation [WPF], duration
Timelines [WPF], description
duration of animations [WPF]
155034ef-7d00-4416-a73c-b1713992d2eb

How to: Set a Duration for an Animation

A xref:System.Windows.Media.Animation.Timeline represents a segment of time and the length of that segment is determined by the timeline's xref:System.Windows.Duration. When a xref:System.Windows.Media.Animation.Timeline reaches the end of its duration, it stops playing. If the xref:System.Windows.Media.Animation.Timeline has child timelines, they stop playing as well. In the case of an animation, the xref:System.Windows.Duration specifies how long the animation takes to transition from its starting value to its ending value.

You can specify a xref:System.Windows.Duration with a specific, finite time or the special values xref:System.Windows.Duration.Automatic%2A or xref:System.Windows.Duration.Forever%2A. An animation's duration must always be a time value, because an animation must always have a defined, finite length—otherwise, the animation would not know how to transition between its target values. Container timelines (xref:System.Windows.Media.Animation.TimelineGroup objects), such as xref:System.Windows.Media.Animation.Storyboard and xref:System.Windows.Media.Animation.ParallelTimeline, have a default duration of xref:System.Windows.Duration.Automatic%2A, which means they automatically end when their last child stops playing.

In the following example, the width, height and fill color of a xref:System.Windows.Shapes.Rectangle is animated. Durations are set on animation and container timelines resulting in animation effects including controlling the perceived speed of an animation and overriding the duration of child timelines with the duration of a container timeline.

Example

[!code-xamltimingbehaviors_snip#DurationExampleWholePage]

See also