Duration Structure
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Represents the duration of time that a Timeline is active.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/> -or- <object property="Automatic" .../> -or- <object property="Forever" .../>
XAML Values
In the grammar, [] indicates optional values, the [] are not literals. The : (colon) and . (period) characters are both literals, and delimit the h:m:s string form of a common timespan, or the optional days and fractionalSeconds values.
The Duration type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Add | Adds the value of the specified Duration to this Duration. |
![]() ![]() | Compare | Compares one Duration value to another. |
![]() | Equals(Duration) | Determines whether a specified Duration is equal to this Duration. |
![]() | Equals(Object) | Determines whether a specified object is equal to a Duration. (Overrides ValueType::Equals(Object).) |
![]() ![]() | Equals(Duration, Duration) | Determines whether two Duration values are equal. |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Gets a hash code for this object. (Overrides ValueType::GetHashCode().) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | Plus | Adds one Duration to this Duration. |
![]() | Subtract | Subtracts the specified Duration from this Duration. |
![]() | ToString | Converts a Duration to a String representation. (Overrides ValueType::ToString().) |
| Name | Description | |
|---|---|---|
![]() ![]() | Addition | Adds two Duration values together. |
![]() ![]() | Equality | Determines whether two Duration cases are equal. |
![]() ![]() | GreaterThan | Determines if one Duration is greater than another. |
![]() ![]() | GreaterThanOrEqual | Determines whether a Duration is greater than or equal to another. |
![]() ![]() | Implicit(TimeSpan to Duration) | Implicitly creates a Duration from a given TimeSpan. |
![]() ![]() | Inequality | Determines if two Duration cases are not equal. |
![]() ![]() | LessThan | Determines if a Duration is less than the value of another instance. |
![]() ![]() | LessThanOrEqual | Determines if a Duration is less than or equal to another. |
![]() ![]() | Subtraction | Subtracts the value of one Duration from another. |
![]() ![]() | UnaryPlus | Returns the specified Duration. |
Specifying a Duration by only an integer without any time span literal characters such as : or . will result in a Duration of that number of days! This is seldom the intended result. Usually you specify animation durations in seconds. As such, the Duration string must include preceding 0 values for hours and minutes, along with the appropriate literal : characters as separators between hours, minutes and seconds. For instance, to specify a Duration of five seconds, the Duration string would be "0:0:5" ("0:0:05" is equivalent).
Duration can be set on either a Storyboard or an animation.
Automatic and Forever
Automatic and Forever are values that hold special meaning for a Duration property value, and are represented by the static properties Automatic and Forever in the managed API for Windows Phone. For details, see Animations for Windows Phone.
The Automatic value applied in either XAML or code results in different behavior on the Storyboard as opposed to an animation. For Storyboard, the Automatic duration time behavior is equal to the end time of its latest ending child animation, such that no clipping of any of the child animation durations occurs. For animations, the Automatic duration is a time span of 1 second (0:0:1). This short duration is seldom desirable, but this default provides you the opportunity to see the animation start during testing. This is better debugging information than never having the animation run, as would occur with a 0 duration.
A Duration of Forever for an animation is part of a deprecated usage, and is seldom used. A Duration of Forever would result in an animation that never advanced from its starting value, no matter what values were provided for From/To, key frames, and so on. If you want an animation to repeat continuously, use RepeatBehavior="Forever", not Duration="Forever".
Duration does not support an object element syntax for XAML, and you cannot declare a Duration as a resource dictionary item in XAML. In XAML you should always specify Duration -type properties in the attribute syntax shown here.
JavaScript API Notes
Creating a Duration in the JavaScript API for Windows Phone is only possible through a type conversion syntax when setting a property such as Duration, with the value specified as a string. The string is generally specified in same format as TimeSpan. Duration can also take the literals Automatic and Forever.
In the managed API, you can create a Duration using the constructors.




