RepeatBehavior Structure
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Describes how a Timeline repeats its simple duration.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
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 the specified object is equal to this RepeatBehavior. (Overrides ValueType::Equals(Object).) |
![]() | Equals(RepeatBehavior) | Returns a value that indicates whether the specified RepeatBehavior is equal to this RepeatBehavior. |
![]() ![]() | Equals(RepeatBehavior, RepeatBehavior) | Indicates whether the two specified RepeatBehavior values are equal. |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object 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. (Overrides ValueType::ToString().) |
![]() | ToString(IFormatProvider) | Returns a string representation of this RepeatBehavior with the specified format. |
| Name | Description | |
|---|---|---|
![]() ![]() | Equality | Indicates whether the two specified RepeatBehavior values are equal. |
![]() ![]() | Inequality | Indicates whether the two RepeatBehavior values are not equal. |
| Name | Description | |
|---|---|---|
![]() ![]() | IFormattable::ToString | Infrastructure. For a description of this member, see ToString. |
There are three types of RepeatBehavior behaviors:
TimeSpan - 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.
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.
Forever - the Timeline repeats indefinitely.
Object element usage in XAML is possible but has no practical usage. You cannot declare a RepeatBehavior as a usable, shareable object in a ResourceDictionary.
In the XAML usage shown, [] indicates optional values; the [] are not literals. The : (colon) and . (period) characters, as well as the x for the iterations form, are literals.
JavaScript API Notes
Creating a RepeatBehavior in the JavaScript API is only possible through a type-conversion syntax when setting a property such as RepeatBehavior that takes a RepeatBehavior, with the value specified as a string interpreted by the grammar.
In managed code, you can create a RepeatBehavior using the constructors.
The following example shows several different ways to set the RepeatBehavior of an animation and how these settings can affect your animation.
<StackPanel Margin="20"> <StackPanel.Resources> <Storyboard x:Name="myStoryboard"> <!-- 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> </StackPanel.Resources> <!-- Create several rectangles to animate. --> <Rectangle Name="ForeverRepeatingRectangle" Fill="Red" Width="50" Height="20" /> <Rectangle Name="FourSecondsRepeatingRectangle" Fill="Blue" Width="50" Height="20" /> <Rectangle Name="TwiceRepeatingRectangle" Fill="Yellow" Width="50" Height="20" /> <Rectangle Name="HalfRepeatingRectangle" Fill="Green" Width="50" Height="20" /> <Rectangle Name="OneSecondRepeatingRectangle" Fill="Orange" Width="50" Height="20" /> <!-- Create buttons to restart and stop the animations. --> <Button Content="Restart Animation" Click="Start_Animation" /> </StackPanel>
private void Start_Animation(object sender, RoutedEventArgs e) { myStoryboard.Begin(); }






