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.

Namespace:  System.Windows.Media.Animation
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

Syntax

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
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.

Top

Properties

  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.

Top

Methods

  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.

Top

Operators

  Name Description
Equality Indicates whether the two specified RepeatBehavior values are equal.
Inequality Indicates whether the two RepeatBehavior values are not equal.

Top

Explicit Interface Implementations

  Name Description
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.

<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();
}

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

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.

See Also

Reference

System.Windows.Media.Animation Namespace

Other Resources

Animations, motion, and output for Windows Phone