RepeatBehavior Property
Collapse the table of content
Expand the table of content

Timeline.RepeatBehavior Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the repeating behavior of this timeline.

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

public RepeatBehavior RepeatBehavior { get; set; }
<timeline RepeatBehavior="repeatBehaviorValue"/>

XAML Values


A RepeatBehavior expressed as a string. This can be an iteration count or a timespan string. For more information, see RepeatBehavior.

Property Value

Type: System.Windows.Media.Animation.RepeatBehavior
An iteration Count that specifies the number of times the timeline should play, a TimeSpan value that specifies the total length of this timeline's active period, or the special value Forever, which specifies that the timeline should repeat indefinitely. The default value is a RepeatBehavior with a Count of 1, which indicates that the timeline plays once.

Dependency property identifier field: RepeatBehaviorProperty

Creating a RepeatBehavior in XAML is possible through a type conversion syntax when setting a property that takes a RepeatBehavior as an attribute string. Basically, a RepeatBehavior can be defined as a timespan string, a #x string, or the special value Forever.

If an iteration Count is specified and the timeline's AutoReverse property is set to true, a single repetition consists of one forward iteration and one backward iteration. A timeline with an AutoReverse property set to true an iteration Count of 2 would play forwards, then backwards, then forwards again, and then backwards again.

Instead of specifying the number of times a timeline plays, you can also specify the total length of time you want the timeline to play. For a timeline to repeat, this Duration value should be greater than the timeline's Duration. For example, a timeline with a Duration of 2 seconds and a Duration of 4 seconds will play twice. If the Duration is less than the timeline's Duration, the timeline's active period is cut short.

This property applies both to specific animations and to the parent storyboard. Generally for an animation in a storyboard, you should apply the RepeatBehavior to the storyboard, because otherwise the parent storyboard default of 1x will prevent any child repeat behaviors from being applied. But you might specify repeat behaviors on child animations if they are intended to run fewer seconds or iterations than the parent storyboard.

For more information about repeating timelines, see Animations, motion, and output for Windows Phone.

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">
        <Storyboard x:Name="myStoryboard">

            <!-- Create an animation that repeats indefinitely. -->
              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. -->
              From="50" To="300" Duration="0:0:2" RepeatBehavior="0:0:4" />

            <!-- Create an animation that repeats twice. -->
              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. -->
              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. -->
              From="50" To="300" Duration="0:0:2" RepeatBehavior="0:0:1" />

    <!-- 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" />


private void Start_Animation(object sender, RoutedEventArgs e)

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft