This documentation is archived and is not being maintained.

Timeline.RepeatBehavior Property

Gets or sets the repeating behavior of this timeline.

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

member RepeatBehavior : RepeatBehavior with get, set

<object RepeatBehavior="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 the 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.

Identifier field


Metadata properties set to true


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 RepeatBehavior.Duration value should be greater than the timeline's Duration. For example, a timeline with a Duration of 2 seconds and a RepeatBehavior.Duration of 4 seconds will play twice. If the RepeatBehavior.Duration is less than the timeline's Duration, the timeline's active period is cut short.

For more information about repeating timelines, see Animation Overview.

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

          <EventTrigger SourceName="restartButton" RoutedEvent="Button.Click">
            <BeginStoryboard Name="myBeginStoryboard">

                <!-- 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" />          
          <EventTrigger SourceName="stopButton" RoutedEvent="Button.Click">
            <StopStoryboard BeginStoryboardName="myBeginStoryboard" />

For the complete sample, see Animation Timing Behavior Sample.

More Code

How to: Specify Whether a Timeline Automatically ReversesA timeline's AutoReverse property determines whether it plays in reverse after it completes a forward iteration. The following example shows several animations with identical duration and target values, but with different AutoReverse settings. To demonstrate how the AutoReverse property behaves with different RepeatBehavior settings, some animations are set to repeat. The last animation shows how the AutoReverse property works on nested timelines.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.