Jaa


RepeatBehavior Struct

Definition

Describes how a Timeline repeats its simple duration.

/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
struct RepeatBehavior
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public struct RepeatBehavior
Public Structure RepeatBehavior
<object property="iterationsx"/>
- or -
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
- or -
<object property="Forever"/>
Inheritance
RepeatBehavior
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

This 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="ForeverRepeatingTransform" 
              Storyboard.TargetProperty="ScaleX" 
              From="1" To="5" Duration="0:0:2" RepeatBehavior="Forever" />

            <!-- Create an animation that repeats for four seconds. Because
                 the animation is 2 seconds each, you get two repeats. -->
            <DoubleAnimation 
              Storyboard.TargetName="FourSecondsRepeatingTransform" 
              Storyboard.TargetProperty="ScaleX"
              From="1" To="5" Duration="0:0:2" RepeatBehavior="0:0:4" 
              EnableDependentAnimation="True"/>

            <!-- Create an animation that repeats twice. -->
            <DoubleAnimation 
              Storyboard.TargetName="TwiceRepeatingTransform" 
              Storyboard.TargetProperty="ScaleX" 
              From="1" To="5" Duration="0:0:2" RepeatBehavior="2x" 
              EnableDependentAnimation="True"/>

            <!-- 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="HalfRepeatingTransform" 
              Storyboard.TargetProperty="ScaleX" 
              From="1" To="5" Duration="0:0:2" RepeatBehavior="0.5x" 
              EnableDependentAnimation="True"/>

            <!-- 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="OneSecondRepeatingTransform" 
              Storyboard.TargetProperty="ScaleX" 
              From="1" To="5" Duration="0:0:2" RepeatBehavior="0:0:1" 
              EnableDependentAnimation="True"/>
        </Storyboard>
    </StackPanel.Resources>

    <!-- Create several rectangles to animate. -->
    <Rectangle Fill="Red" Width="50" Height="20" >
        <Rectangle.RenderTransform>
            <ScaleTransform x:Name="ForeverRepeatingTransform" />
        </Rectangle.RenderTransform>
   </Rectangle>
   <Rectangle Fill="Blue" Width="50" Height="20" >
       <Rectangle.RenderTransform>
           <ScaleTransform x:Name="FourSecondsRepeatingTransform" />
       </Rectangle.RenderTransform>
   </Rectangle>
   <Rectangle Fill="Yellow" Width="50" Height="20" >
       <Rectangle.RenderTransform>
           <ScaleTransform x:Name="TwiceRepeatingTransform" />
       </Rectangle.RenderTransform>
   </Rectangle>
   <Rectangle Fill="Green" Width="50" Height="20" >
       <Rectangle.RenderTransform>
           <ScaleTransform x:Name="HalfRepeatingTransform" />
       </Rectangle.RenderTransform>
   </Rectangle>
   <Rectangle Fill="Orange" Width="50" Height="20" >
       <Rectangle.RenderTransform>
           <ScaleTransform x:Name="OneSecondRepeatingTransform" />
       </Rectangle.RenderTransform>
   </Rectangle>

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

This example shows how you can set the RepeatBehavior in code. The animations are the same as in the previous example, but have the x:Name attribute set, and the RepeatBehavior is set in the Start_Animation method rather than in XAML.

<Storyboard x:Name="myStoryboard">

    <!-- Create an animation that repeats indefinitely. -->
    <DoubleAnimation x:Name="ForeverRepeatingAnimation"
                     Storyboard.TargetName="ForeverRepeatingTransform" 
                     Storyboard.TargetProperty="ScaleX" 
                     From="1" To="5" Duration="0:0:2"  />

    <!-- Create an animation that repeats for four seconds. Because 
        the animation is 2 seconds each, you get two repeats. -->
    <DoubleAnimation x:Name="FourSecondsRepeatingAnimation"
                     Storyboard.TargetName="FourSecondsRepeatingTransform" 
                     Storyboard.TargetProperty="ScaleX"
                     From="1" To="5" Duration="0:0:2"  
                     EnableDependentAnimation="True"/>

    <!-- Create an animation that repeats twice. -->
    <DoubleAnimation x:Name="TwiceRepeatingAnimation"
                     Storyboard.TargetName="TwiceRepeatingTransform" 
                     Storyboard.TargetProperty="ScaleX" 
                     From="1" To="5" Duration="0:0:2"  
                     EnableDependentAnimation="True"/>
</Storyboard>
private void Start_Animation(object sender, RoutedEventArgs e)
{
    // Set RepeatBehavior of Forever.
    var repeatBehavior = new RepeatBehavior();
    repeatBehavior.Type = RepeatBehaviorType.Forever;
    ForeverRepeatingAnimation.RepeatBehavior = repeatBehavior;

    // Set RepeatBehavior with Duration of 4 seconds.
    FourSecondsRepeatingAnimation.RepeatBehavior = new RepeatBehavior(new TimeSpan(0, 0, 4));

    // Set RepeatBehavior with Count of 2.
    TwiceRepeatingAnimation.RepeatBehavior = new RepeatBehavior(2);

    myStoryboard.Begin();
}

Remarks

There are three types of RepeatBehavior behaviors:

  • Time span: specifies the active duration of a Timeline, possibly repeating the animation if the Timeline.Duration is shorter. For example, a Timeline with a simple Timeline.Duration value of 1 second and a RepeatBehavior.Duration value of 2.5 seconds will run for 2.5 iterations, and 2.5 seconds.
  • Iteration count: specifies the number of times the simple duration of a Timeline plays. The default iteration count is 1.0, and this 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 Count.
  • Forever: the Timeline repeats indefinitely.

A RepeatBehavior should only contain non-zero values for one of its two possible data properties Count or Duration. If the RepeatBehaviorType is Count, then the Count member of a RepeatBehavior is the relevant value. If the RepeatBehaviorType is Duration, then the Duration member of a RepeatBehavior is the relevant value. If the RepeatBehaviorType is Forever, then neither Count nor Duration are relevant; the repeat behavior is such that the targeted animation will repeat continuously without a limit.

Notes on XAML syntax

You cannot declare a RepeatBehavior as a shareable object in a ResourceDictionary.

Projection and members of RepeatBehavior

If you are using a Microsoft .NET language (C# or Microsoft Visual Basic), then RepeatBehavior has non-data members available, and its data members Count, Duration and Type are exposed as read-write properties, not fields.

If you are using Visual C++ component extensions (C++/CX), then RepeatBehavior has non-data members available, and its data members Count, Duration and Type are exposed as read-only properties, not fields.

If you are programming with C++ using the Windows Runtime Template Library (WRL), then only the data member fields Count, Duration, and Type exist as members of RepeatBehavior, and you cannot use the utility methods or properties listed in the members table. WRL code can access similar utility methods that exist on the RepeatBehaviorHelper class.

Fields

Count

The number of times a Timeline should repeat.

Duration

The time span for which a Timeline should repeat.

Type

The mode or type of repeat behavior that this instance represents, as a value of the enumeration.

Applies to