The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public struct Duration
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
<object property="Automatic" .../>
<object property="Forever" .../>

XAML Values


An integer value greater than or equal to 0 that specifies the number of days.


An integer value between 0 and 23 that specifies the number of hours. If you specify a Duration as a XAML attribute, an hours component is required, even if is 0.


An integer value between 0 and 59 that specifies the number of minutes. Set hours:minutes components as 0:0 if you are setting only a seconds component.


An integer value between 0 and 59 that specifies the number of seconds. Set hours:minutes components as 0:0 if you are setting only a seconds component.


Optional. A decimal value consisting of 1 to 7 positions past the decimal point, which specifies fractional seconds.


The literal string Automatic; see "Automatic and Forever" section in Remarks.


The literal string Forever; see "Automatic and Forever" section in Remarks.

  • 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.

Public methodDurationInitializes a new instance of the Duration structure with the supplied TimeSpan value.

Public propertyStatic memberAutomaticGets a Duration value that is automatically determined.
Public propertyStatic memberForeverGets a Duration value that represents an infinite interval.
Public propertyHasTimeSpanGets a value that indicates if this Duration represents a TimeSpan value.
Public propertyTimeSpanGets the TimeSpan value that this Duration represents.

Public methodAddAdds the value of the specified Duration to this Duration.
Public methodStatic memberCompareCompares one Duration value to another.
Public methodEquals(Duration)Determines whether a specified Duration is equal to this Duration.
Public methodEquals(Object)Determines whether a specified object is equal to a Duration. (Overrides ValueType.Equals(Object).)
Public methodStatic memberEquals(Duration, Duration)Determines whether two Duration values are equal.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeGets a hash code for this object. (Overrides ValueType.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberPlusAdds one Duration to this Duration.
Public methodSubtractSubtracts the specified Duration from this Duration.
Public methodToStringConverts a Duration to a String representation. (Overrides ValueType.ToString().)

Public operatorStatic memberAdditionAdds two Duration values together.
Public operatorStatic memberEqualityDetermines whether two Duration cases are equal.
Public operatorStatic memberGreaterThanDetermines if one Duration is greater than another.
Public operatorStatic memberGreaterThanOrEqualDetermines whether a Duration is greater than or equal to another.
Public operatorStatic memberImplicit(TimeSpan to Duration)Implicitly creates a Duration from a given TimeSpan.
Public operatorStatic memberInequalityDetermines if two Duration cases are not equal.
Public operatorStatic memberLessThanDetermines if a Duration is less than the value of another instance.
Public operatorStatic memberLessThanOrEqualDetermines if a Duration is less than or equal to another.
Public operatorStatic memberSubtractionSubtracts the value of one Duration from another.
Public operatorStatic memberUnaryPlusReturns 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.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.