This topic has not yet been rated - Rate this topic

RepeatBehavior Structure

Describes how a Timeline repeats its simple duration.

Namespace:  System.Windows.Media.Animation
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
'Declaration
<TypeConverterAttribute(GetType(RepeatBehaviorConverter))> _
Public Structure RepeatBehavior _
	Implements IFormattable
<object property="iterationCountx"/>- or -<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>- or -<object property="[days.]hours:minutes"/>- or - <object property="days"/>- or -<object property="Forever"/>

XAML Values

Items in square brackets ([ and ]) are optional.

iterationCount

System.Double

A value greater than or equal to 0 that specifies the number of times a timeline should play. For more information, see the Count property.

days

System.Int32

A value greater than or equal to 0 that specifies the number of days for a Timeline object's active duration. For more information, see the Duration property.

hours

System.Int32

A value between 0 and 23 that specifies the number of hours for a Timeline object's active duration. For more information, see the Duration property.

minutes

System.Int32

A value between 0 and 59 that specifies the number of minutes for a Timeline object's active duration. For more information, see the Duration property.

seconds

System.Double

A value between 0 and 59 that specifies the number of seconds for a Timeline object's active duration. For more information, see the Duration property.

fractionalSeconds

System.Int32

A value consisting of 1 to 7 digits that represents fractional seconds.

The RepeatBehavior type exposes the following members.

  NameDescription
Public methodRepeatBehavior(Double)Initializes a new instance of the RepeatBehavior structure with the specified iteration count.
Public methodRepeatBehavior(TimeSpan)Initializes a new instance of the RepeatBehavior structure with the specified repeat duration.
Top
  NameDescription
Public propertyCountGets the number of times a Timeline should repeat.
Public propertyDurationGets the total length of time a Timeline should play.
Public propertyStatic memberForeverGets a RepeatBehavior that specifies an infinite number of repetitions.
Public propertyHasCountGets a value that indicates whether the repeat behavior has a specified iteration count.
Public propertyHasDurationGets a value that indicates whether the repeat behavior has a specified repeat duration.
Top
  NameDescription
Public methodEquals(Object)Indicates whether this instance is equal to the specified object. (Overrides ValueType.Equals(Object).)
Public methodEquals(RepeatBehavior)Returns a value that indicates whether this instance is equal to the specified RepeatBehavior.
Public methodStatic memberEquals(RepeatBehavior, RepeatBehavior)Indicates whether the two specified RepeatBehavior structures are equal.
Public methodGetHashCode Returns the hash code of this instance. (Overrides ValueType.GetHashCode.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns a string representation of this RepeatBehavior instance. (Overrides ValueType.ToString.)
Public methodToString(IFormatProvider)Returns a string representation of this RepeatBehavior instance with the specified format.
Top
  NameDescription
Public operatorStatic memberEqualityIndicates whether the two specified RepeatBehavior instances are equal.
Public operatorStatic memberInequalityIndicates whether the two RepeatBehavior instances are not equal.
Top
  NameDescription
Explicit interface implemetationPrivate methodIFormattable.ToStringFormats the value of the current instance using the specified format.
Top

There are three types of RepeatBehavior behaviors:

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

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

  • Forever - the Timeline repeats indefinitely.

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. -->
<Page 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  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>

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

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

For the complete sample, see Animation Timing Behavior Sample.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.