RepeatBehavior Structure

Describes how a Timeline repeats its simple duration.

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

Syntax

'Declaration
Public Structure RepeatBehavior _
    Implements IFormattable
public struct RepeatBehavior : IFormattable
<object property="iterationsx"/>
- or -
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
- or -
<object property="Forever"/>

XAML Values

  • iterationsx
    The iterations placeholder in the iterations form is an integer, specifying the number of times that an animation should repeat. The x is a literal, lower-case character x. (A way to remember this convention is to think of x as a multiplication character, that is, "3x" means "3 times.")

  • days
    Optional. An integer value greater than or equal to 0 that specifies the number of days.

  • hours
    Required, even if 0. An integer value between 0 and 23 that specifies the number of hours.

  • minutes
    Optional if only hours are desired, but needs to be at least set to 0 if you intend to set a seconds value. An integer value between 0 and 59 that specifies the number of minutes.

  • seconds
    Optional if only hours/minutes are desired. An integer value between 0 and 59 that specifies the number of seconds.

  • fractionalSeconds
    Optional. A value consisting of 1 to 7 digits of decimal precision that specifies fractional seconds.

  • Forever
    The literal "Forever"; see Remarks.

The RepeatBehavior type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone RepeatBehavior(Double) Initializes a new instance of the RepeatBehavior structure with the specified iteration count.
Public methodSupported by Silverlight for Windows Phone RepeatBehavior(TimeSpan) Initializes a new instance of the RepeatBehavior structure with the specified repeat duration.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone Count Gets the number of times a Timeline should repeat.
Public propertySupported by Silverlight for Windows Phone Duration Gets the total length of time a Timeline should play.
Public propertyStatic memberSupported by Silverlight for Windows Phone Forever Gets a RepeatBehavior that specifies an infinite number of repetitions.
Public propertySupported by Silverlight for Windows Phone HasCount Gets a value that indicates whether the repeat behavior has a specified iteration count.
Public propertySupported by Silverlight for Windows Phone HasDuration Gets a value that indicates whether the repeat behavior has a specified repeat duration.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Object) Indicates whether the specified object is equal to this RepeatBehavior. (Overrides ValueType.Equals(Object).)
Public methodSupported by Silverlight for Windows Phone Equals(RepeatBehavior) Returns a value that indicates whether the specified RepeatBehavior is equal to this RepeatBehavior.
Public methodStatic memberSupported by Silverlight for Windows Phone Equals(RepeatBehavior, RepeatBehavior) Indicates whether the two specified RepeatBehavior values are equal.
Protected methodSupported by Silverlight for Windows Phone 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.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Returns the hash code of this instance. (Overrides ValueType.GetHashCode().)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToString() Returns a string representation of this RepeatBehavior. (Overrides ValueType.ToString().)
Public methodSupported by Silverlight for Windows Phone ToString(IFormatProvider) Returns a string representation of this RepeatBehavior with the specified format.

Top

Operators

  Name Description
Public operatorStatic memberSupported by Silverlight for Windows Phone Equality Indicates whether the two specified RepeatBehavior values are equal.
Public operatorStatic memberSupported by Silverlight for Windows Phone Inequality Indicates whether the two RepeatBehavior values are not equal.

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate methodSupported by Silverlight for Windows Phone IFormattable.ToString Infrastructure. For a description of this member, see ToString.

Top

Remarks

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.

Examples

The following example shows several different ways to set the RepeatBehavior of an animation and how these settings can affect your animation.

Run this sample

<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 Margin="10" Content="Restart Animation" Click="Start_Animation" />


</StackPanel>
<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 Margin="10" Content="Restart Animation" Click="Start_Animation" />


</StackPanel>
<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 Margin="10" Content="Restart Animation" Click="Start_Animation" />


</StackPanel>
<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 Margin="10" Content="Restart Animation" Click="Start_Animation" />


</StackPanel>
private void Start_Animation(object sender, RoutedEventArgs e)
{
    myStoryboard.Begin();
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.