Timeline.Duration Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the length of time for which this timeline plays, not counting repetitions.

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


Public Property Duration As Duration
public Duration Duration { get; set; }
<timeline Duration="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
<timeline Duration="Automatic" .../>
<timeline Duration="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 Duration .

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

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

Property Value

Type: System.Windows.Duration
The timeline's simple duration: the amount of time this timeline takes to complete a single forward iteration. The default value is Automatic.


Dependency property identifier field: DurationProperty

A timeline's simple duration constitutes the time for a single forward iteration versus the total play time, which includes repetitions.

See Duration for details on the XAML attribute format you use to specify a Duration value, in XAML. Creating a Duration in XAML is possible through a type conversion syntax when setting a property that takes a Duration as an attribute string. Basically, a Duration can be defined as a timespan string, or the special value Automatic.

You can programmatically set a new value for Duration on a running animation, and the value will apply immediately. The new current state of the animation will reflect the progress of the animation that had already run prior to the change, with that same progress applied towards the new Duration. You can get the Duration value programmatically using value=object.Duration syntax. However, if the Duration for an animation is not explicitly set (either programmatically or XAML), then the value of object.Duration will be null. A null value for Duration has the same implied effect on an animation as does a Duration explicitly set to Automatic.

If the AutoReverse property is set to true, the timeline plays for twice the length of time specified by its Duration.

This property applies both to specific animations and to the parent storyboard. For an animation in a storyboard, if you set a Duration other than the default Automatic at the storyboard level, make sure you are not unintentionally clipping the durations of child animations.


Animations cannot have a Duration of Forever. If you set the Duration to Forever, an exception will be thrown.


The duration of a Storyboard is determined by the duration of its child timelines. For example, the Storyboard below will run for six seconds (duration of 6 seconds) because that is when its last child Timeline (DoubleAnimation) ends.


Code has been omitted from the following examples, which are provided for illustrative purposed only.

    <DoubleAnimation Duration="0:0:2" .../>
    <DoubleAnimation Duration="0:0:4" BeginTime="0:0:2" .../>

Examples of <Type>Animations include DoubleAnimation, PointAnimation, ColorAnimation, etc. If no Duration is specified for these types of animations, they will run for one second.

  <!-- With no Duration specified, this animation will run for 
       one second -->
  <DoubleAnimation .../>

Examples of <Type>AnimationUsingKeyFrames include DoubleAnimationUsingKeyFrames, PointAnimationUsingKeyFrames, etc. If no Duration is specified for these types of animations they will run until all key frames are finished.


    <!-- This key frame animation will end at 4.5 seconds
         Because that is when its last KeyFrame KeyTime ends. -->
    <DoubleAnimationUsingKeyFrames ...>
      <LinearDoubleKeyFrame ... KeyTime="0:0:3" />
      <DiscreteDoubleKeyFrame ... KeyTime="0:0:3.5" />
      <DiscreteDoubleKeyFrame ... KeyTime="0:0:4" />
      <DiscreteDoubleKeyFrame ... KeyTime="0:0:4.5" />

Version Information


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.