Export (0) Print
Expand All

Duration Structure

Represents the duration of time that a Timeline is active.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

'Declaration
Public Structure Duration
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
-or-
<object property="Automatic" .../>
-or-
<object property="Forever" .../>

XAML Values

days

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

hours

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.

minutes

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.

seconds

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.

fractionalSeconds

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

Automatic

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

Forever

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.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneDurationInitializes a new instance of the Duration structure with the supplied TimeSpan value.
Top

  NameDescription
Public propertyStatic memberSupported by Silverlight for Windows PhoneAutomaticGets a Duration value that is automatically determined.
Public propertyStatic memberSupported by Silverlight for Windows PhoneForeverGets a Duration value that represents an infinite interval.
Public propertySupported by Silverlight for Windows PhoneHasTimeSpanGets a value that indicates if this Duration represents a TimeSpan value.
Public propertySupported by Silverlight for Windows PhoneTimeSpanGets the TimeSpan value that this Duration represents.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneAddAdds the value of the specified Duration to this Duration.
Public methodStatic memberSupported by Silverlight for Windows PhoneCompareCompares one Duration value to another.
Public methodSupported by Silverlight for Windows PhoneEquals(Duration)Determines whether a specified Duration is equal to this Duration.
Public methodSupported by Silverlight for Windows PhoneEquals(Object)Determines whether a specified object is equal to a Duration. (Overrides ValueType.Equals(Object).)
Public methodStatic memberSupported by Silverlight for Windows PhoneEquals(Duration, Duration)Determines whether two Duration values are equal.
Protected methodSupported by Silverlight for Windows PhoneFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneGetHashCodeGets a hash code for this object. (Overrides ValueType.GetHashCode.)
Public methodSupported by Silverlight for Windows PhoneGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberSupported by Silverlight for Windows PhonePlusAdds one Duration to this Duration.
Public methodSupported by Silverlight for Windows PhoneSubtractSubtracts the specified Duration from this Duration.
Public methodSupported by Silverlight for Windows PhoneToStringConverts a Duration to a String representation. (Overrides ValueType.ToString.)
Top

  NameDescription
Public operatorStatic memberSupported by Silverlight for Windows PhoneAdditionAdds two Duration values together.
Public operatorStatic memberSupported by Silverlight for Windows PhoneEqualityDetermines whether two Duration cases are equal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneGreaterThanDetermines if one Duration is greater than another.
Public operatorStatic memberSupported by Silverlight for Windows PhoneGreaterThanOrEqualDetermines whether a Duration is greater than or equal to another.
Public operatorStatic memberSupported by Silverlight for Windows PhoneWidening(TimeSpan to Duration)Implicitly creates a Duration from a given TimeSpan.
Public operatorStatic memberSupported by Silverlight for Windows PhoneInequalityDetermines if two Duration cases are not equal.
Public operatorStatic memberSupported by Silverlight for Windows PhoneLessThanDetermines if a Duration is less than the value of another instance.
Public operatorStatic memberSupported by Silverlight for Windows PhoneLessThanOrEqualDetermines if a Duration is less than or equal to another.
Public operatorStatic memberSupported by Silverlight for Windows PhoneSubtractionSubtracts the value of one Duration from another.
Public operatorStatic memberSupported by Silverlight for Windows PhoneUnaryPlusReturns the specified Duration.
Top

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 Silverlight. For details, see Animation Overview.

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

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

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

Community Additions

ADD
Show:
© 2014 Microsoft