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
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>- or -<object property="[days.]hours:minutes"/>- or -<object property="Automatic"/>- or -<object property="Forever"/>
Thetype exposes the following members.
|Add||Adds the value of the specified instance of to the value of the current instance.|
|Compare||Compares one value to another.|
|Equals(Duration)||Determines whether a specified is equal to this instance of .|
|Equals(Object)||Determines whether a specified object is equal to an instance of . (Overrides ValueType.Equals(Object).)|
|Equals(Duration, Duration)||Determines whether two instances of 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 .|
|Subtract||Subtracts the value of the specified instance of from this instance.|
|ToString||Converts an instance of to a String representation. (Overrides ValueType.ToString().)|
|Addition||Adds two instances of together.|
|Equality||Determines whether two instances of are equal.|
|GreaterThan||Determines if one instance of is greater than another.|
|GreaterThanOrEqual||Determines whether an instance of is greater than or equal to another instance.|
|Implicit(TimeSpan to Duration)||Implicitly creates a from a given TimeSpan.|
|Inequality||Determines if two instances of are not equal.|
|LessThan||Determines if the value of one instance of is less than the value of another instance.|
|LessThanOrEqual||Determines if the value of one instance of is less than or equal to the value of another instance.|
|Subtraction||Subtracts the value of one instance of from another.|
|UnaryPlus||Returns the specified instance of .|
A Timeline represents a segment of time and the length of that segment is determined by the timeline's . 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 specifies how long the animation takes to transition from its starting value to its ending value.
You can specify a 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