Skip to content

Latest commit

 

History

History
124 lines (88 loc) · 7.54 KB

File metadata and controls

124 lines (88 loc) · 7.54 KB
-api-id -api-type
T:Microsoft.UI.Xaml.Media.Animation.RepeatBehavior
winrt struct

RepeatBehavior

-description

Describes how a Timeline repeats its simple duration.

-xaml-syntax

<object property="iterationsx"/>
- or -
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
- or -
<object property="Forever"/>

-xaml-values

iterationsx
iterationsxThe 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.) Iterations set the Count data; a TimeSpan value does not set the Count data.
days
daysOptional. An integer value greater than or equal to 0 that specifies the number of days.
hours
hoursRequired, even if 0. An integer value between 0 and 23 that specifies the number of hours.
minutes
minutesOptional if only hours are desired, but must be set to at least 0 if you intend to set a seconds value. An integer value between 0 and 59 that specifies the number of minutes.
seconds
secondsOptional if only hours/minutes are desired. An integer value between 0 and 59 that specifies the number of seconds.
fractionalSeconds
fractionalSecondsOptional. A value consisting of 1 to 7 digits of decimal precision that specifies fractional seconds.
Forever
ForeverThe literal Forever; see Remarks.

-struct-fields

-field Count

The number of times a Timeline should repeat.

-field Duration

The time span for which a Timeline should repeat.

-field Type

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

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

-examples

This example shows several different ways to set the RepeatBehavior of an animation and how these settings can affect your animation.

[!code-xamlRepeatBehavior]

[!code-csharpRepeatBehavior_code]

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

-see-also