RepeatBehavior Structure
Describes how a Timeline repeats its simple duration.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[TypeConverterAttribute(typeof(RepeatBehaviorConverter))] public value class RepeatBehavior : IFormattable
<object property="iterationCountx"/>- or -<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>- or -<object property="[days.]hours:minutes"/>- or - <object property="days"/>- or -<object property="Forever"/>
XAML Values
Items in square brackets ([ and ]) are optional.
The RepeatBehavior type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | RepeatBehavior(Double) | Initializes a new instance of the RepeatBehavior structure with the specified iteration count. |
![]() | RepeatBehavior(TimeSpan) | Initializes a new instance of the RepeatBehavior structure with the specified repeat duration. |
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of times a Timeline should repeat. |
![]() | Duration | Gets the total length of time a Timeline should play. |
![]() ![]() | Forever | Gets a RepeatBehavior that specifies an infinite number of repetitions. |
![]() | HasCount | Gets a value that indicates whether the repeat behavior has a specified iteration count. |
![]() | HasDuration | Gets a value that indicates whether the repeat behavior has a specified repeat duration. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Indicates whether this instance is equal to the specified object. (Overrides ValueType::Equals(Object).) |
![]() | Equals(RepeatBehavior) | Returns a value that indicates whether this instance is equal to the specified RepeatBehavior. |
![]() ![]() | Equals(RepeatBehavior, RepeatBehavior) | Indicates whether the two specified RepeatBehavior structures 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 | Returns the hash code of 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.) |
![]() | ToString() | Returns a string representation of this RepeatBehavior instance. (Overrides ValueType::ToString().) |
![]() | ToString(IFormatProvider) | Returns a string representation of this RepeatBehavior instance with the specified format. |
| Name | Description | |
|---|---|---|
![]() ![]() | Equality | Indicates whether the two specified RepeatBehavior instances are equal. |
![]() ![]() | Inequality | Indicates whether the two RepeatBehavior instances are not equal. |
| Name | Description | |
|---|---|---|
![]() ![]() | IFormattable::ToString | Formats the value of the current instance using the specified format. |
There are three types of RepeatBehavior behaviors:
Iteration Count - specifies the number of times the simple duration of a Timeline plays. The default iteration count is 1.0, and means the Timeline is active for exactly one of its simple durations. A count of 0.5 specifies that the timeline is active for half of its simple duration, while a count of 2 specifies that the timeline repeats its simple duration twice. For more information, see the Count property.
Duration - specifies the length of the Timeline object's active duration. For example, a Timeline with a simple Duration value of 1 second and a RepeatBehavior::Duration value of 2.5 seconds will run for 2.5 iterations.
Forever - the Timeline repeats indefinitely.
This example shows how to use the RepeatBehavior property of a Timeline in order to control the repeat behavior of an animation.
The RepeatBehavior property of a Timeline controls how many times an animation repeats its simple duration. By using RepeatBehavior, you can specify that a Timeline repeats for a certain number of times (an iteration count) or for a specified time period. In either case, the animation goes through as many beginning-to-end runs that it needs in order to fill the requested count or duration.
By default, timelines have a repeat count of 1.0, which means they play one time and do not repeat. However, if you set the RepeatBehavior property of a Timeline to Forever, the timeline repeats indefinitely.
The following example shows how to use the RepeatBehavior property to control the repeat behavior of an animation. The example animates the Width property of five rectangles with each rectangle using a different type of repeat behavior.
<!-- RepeatBehaviorExample.xaml This example shows how to use the RepeatBehavior property to make a timeline repeat. --> <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowTitle="RepeatBehavior Example"> <Border HorizontalAlignment="Stretch"> <StackPanel Margin="20"> <!-- Create several rectangles to animate. --> <Rectangle Name="ForeverRepeatingRectangle" Fill="Orange" Width="50" Height="20" /> <Rectangle Name="FourSecondsRepeatingRectangle" Fill="Orange" Width="50" Height="20" /> <Rectangle Name="TwiceRepeatingRectangle" Fill="Orange" Width="50" Height="20" /> <Rectangle Name="HalfRepeatingRectangle" Fill="Orange" Width="50" Height="20" /> <Rectangle Name="OneSecondRepeatingRectangle" Fill="Orange" Width="50" Height="20" /> <!-- Create buttons to restart and stop the animations. --> <StackPanel Orientation="Horizontal" Margin="0,20,0,0"> <Button Name="restartButton">Start Animations</Button> <Button Name="stopButton" Background="#669900FF">Stop</Button> <StackPanel.Triggers> <EventTrigger SourceName="restartButton" RoutedEvent="Button.Click"> <BeginStoryboard Name="myBeginStoryboard"> <Storyboard> <!-- Create an animation that repeats indefinitely. --> <DoubleAnimation Storyboard.TargetName="ForeverRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="Forever" /> <!-- Create an animation that repeats for four seconds. As a result, the animation repeats twice. --> <DoubleAnimation Storyboard.TargetName="FourSecondsRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="0:0:4" /> <!-- Create an animation that repeats twice. --> <DoubleAnimation Storyboard.TargetName="TwiceRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="2x" /> <!-- Create an animation that repeats 0.5 times. The resulting animation plays for one second, half of its Duration. It animates from 50 to 150. --> <DoubleAnimation Storyboard.TargetName="HalfRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="0.5x" /> <!-- Create an animation that repeats for one second. The resulting animation plays for one second, half of its Duration. It animates from 50 to 150. --> <DoubleAnimation Storyboard.TargetName="OneSecondRepeatingRectangle" Storyboard.TargetProperty="Width" From="50" To="300" Duration="0:0:2" RepeatBehavior="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger SourceName="stopButton" RoutedEvent="Button.Click"> <StopStoryboard BeginStoryboardName="myBeginStoryboard" /> </EventTrigger> </StackPanel.Triggers> </StackPanel> </StackPanel> </Border> </Page>
For the complete sample, see Animation Timing Behavior Sample.
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.
