This documentation is archived and is not being maintained.

Duration Structure

Represents the duration of time that a Timeline is active.

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

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

XAML Values



A value greater than or equal to 0 that describes the number of days spanned by this duration.



A value between 0 and 23 that represents the number of hours spanned by this duration.



A value between 0 and 59 that represents the number of minutes spanned by this duration.



A value between 0 and 59 that represents the number of seconds spanned by this duration



A value consisting of 1 to 7 digits that represents fractional seconds.

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 instance of Duration to the value of the current instance.
Public methodStatic memberCompareCompares one Duration value to another.
Public methodEquals(Duration)Determines whether a specified Duration is equal to this instance of Duration.
Public methodEquals(Object)Determines whether a specified object is equal to an instance of Duration. (Overrides ValueType.Equals(Object).)
Public methodStatic memberEquals(Duration, Duration)Determines whether two instances of Duration are equal.
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeGets a hash code for this instance. (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 memberPlusReturns the specified instance of Duration.
Public methodSubtractSubtracts the value of the specified instance of Duration from this instance.
Public methodToStringConverts an instance of Duration to a String representation. (Overrides ValueType.ToString().)

Public operatorStatic memberAdditionAdds two instances of Duration together.
Public operatorStatic memberEqualityDetermines whether two instances of Duration are equal.
Public operatorStatic memberGreaterThanDetermines if one instance of Duration is greater than another.
Public operatorStatic memberGreaterThanOrEqualDetermines whether an instance of Duration is greater than or equal to another instance.
Public operatorStatic memberImplicit(TimeSpan to Duration)Implicitly creates a Duration from a given TimeSpan.
Public operatorStatic memberInequalityDetermines if two instances of Duration are not equal.
Public operatorStatic memberLessThanDetermines if the value of one instance of Duration is less than the value of another instance.
Public operatorStatic memberLessThanOrEqualDetermines if the value of one instance of Duration is less than or equal to the value of another instance.
Public operatorStatic memberSubtractionSubtracts the value of one instance of Duration from another.
Public operatorStatic memberUnaryPlusReturns the specified instance of Duration.

A Timeline represents a segment of time and the length of that segment is determined by the timeline's Duration. 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 Duration specifies how long the animation takes to transition from its starting value to its ending value.

You can specify a Duration with a specific, finite time or the special values Automatic or Forever. 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 (TimelineGroup objects), such as Storyboard and ParallelTimeline, have a default duration of Automatic, which means they automatically end when their last child stops playing.

In the following example, the width, height and fill color of a 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.

  <StackPanel Margin="20">

    <Rectangle Width="100" Height="100" Name="myRectangle">
        <SolidColorBrush x:Name="MyAnimatedBrush" Color="Black" />

        <!-- Animates the rectangle fill to yellow and width to 300. -->
        <EventTrigger RoutedEvent="Rectangle.Loaded">

            <!-- By default, TimelineGroup objects like Storyboard and ParallelTimeline have 
            a Duration of "Automatic". A TimelineGroup's automatic duration encompasses its 
            last-ending child. In this example, there is only one child of the Storyboard, the
            ParallelTimeline, so when the ParallelTimeline ends, the Storyboard duration will
            automatically end. -->

              <!-- This ParallelTimeline has overriden its default duration of "Automatic" with
              a finite duration of half a second. This will force this Timeline to end after half a
              second even though its child Timelines have a longer duration (2 and 4 seconds respectively). 
              This cuts off the animation prematurely and the rectangle's fill will not go all the way to 
              yellow nor will the rectangle width get all the way to 300. Again, the default duration of a
              ParallelTimeline is "Automatic" so if you remove the finite duration, the ParallelTimeline
              will wait for its child timelines to end before it ends. -->

              <!-- Note: To specify a finite time in XAML, use the syntax of "days:hours:seconds". As mentioned,
              this ParallelTimeline has a duration of half a second. -->
              <ParallelTimeline Duration="0:0:0.5">

                <!-- For Animation Timelines like DoubleAnimation, the duration is one factor that
                determines the rate at which an animation appears to progress. For example, the DoubleAnimation
                below that animates the rectangle height will complete in only one second while the animation
                that animates the width willwill complete in 2 seconds which is relatively fast compared to the DoubleAnimation
                which animates the rectangle width over 4 seconds. -->
                  To="300" Duration="0:0:1" />

                  To="300" Duration="0:0:4" />

                  To="Yellow" Duration="0:0:2" />



.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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