Duration Structure
Represents the duration of time that a Timeline is active.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
The Duration type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Add | Adds the value of the specified instance of Duration to the value of the current instance. |
![]() ![]() | Compare | Compares one Duration value to another. |
![]() | Equals(Duration) | Determines whether a specified Duration is equal to this instance of Duration. |
![]() | Equals(Object) | Determines whether a specified object is equal to an instance of Duration. (Overrides ValueType::Equals(Object).) |
![]() ![]() | Equals(Duration, Duration) | Determines whether two instances of Duration are equal. |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Gets a hash code for this instance. (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 | Returns the specified instance of Duration. |
![]() | Subtract | Subtracts the value of the specified instance of Duration from this instance. |
![]() | ToString | Converts an instance of Duration to a String representation. (Overrides ValueType::ToString().) |
| Name | Description | |
|---|---|---|
![]() ![]() | Addition | Adds two instances of Duration together. |
![]() ![]() | Equality | Determines whether two instances of Duration are equal. |
![]() ![]() | GreaterThan | Determines if one instance of Duration is greater than another. |
![]() ![]() | GreaterThanOrEqual | Determines whether an instance of Duration is greater than or equal to another instance. |
![]() ![]() | Implicit(TimeSpan to Duration) | Implicitly creates a Duration from a given TimeSpan. |
![]() ![]() | Inequality | Determines if two instances of Duration are not equal. |
![]() ![]() | LessThan | Determines if the value of one instance of Duration is less than the value of another instance. |
![]() ![]() | LessThanOrEqual | Determines if the value of one instance of Duration is less than or equal to the value of another instance. |
![]() ![]() | Subtraction | Subtracts the value of one instance of Duration from another. |
![]() ![]() | UnaryPlus | Returns 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.
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <StackPanel Margin="20"> <Rectangle Width="100" Height="100" Name="myRectangle"> <Rectangle.Fill> <SolidColorBrush x:Name="MyAnimatedBrush" Color="Black" /> </Rectangle.Fill> <Rectangle.Triggers> <!-- Animates the rectangle fill to yellow and width to 300. --> <EventTrigger RoutedEvent="Rectangle.Loaded"> <BeginStoryboard> <!-- 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. --> <Storyboard> <!-- 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. --> <DoubleAnimation Storyboard.TargetName="myRectangle" Storyboard.TargetProperty="Height" To="300" Duration="0:0:1" /> <DoubleAnimation Storyboard.TargetName="myRectangle" Storyboard.TargetProperty="Width" To="300" Duration="0:0:4" /> <ColorAnimation Storyboard.TargetName="MyAnimatedBrush" Storyboard.TargetProperty="Color" To="Yellow" Duration="0:0:2" /> </ParallelTimeline> </Storyboard> </BeginStoryboard> </EventTrigger> </Rectangle.Triggers> </Rectangle> </StackPanel> </Page>
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.
