RepeatBehavior Estructura

Definición

Describe cómo una escala de tiempo repite su duración simple.

/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
struct RepeatBehavior
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
public struct RepeatBehavior
Public Structure RepeatBehavior
<object property="iterationsx"/>
- or -
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
- or -
<object property="Forever"/>
Herencia
RepeatBehavior
Atributos

Ejemplos

En este ejemplo se muestran varias maneras diferentes de establecer RepeatBehavior de una animación y cómo esta configuración puede afectar a la animación.

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

En este ejemplo se muestra cómo puede establecer RepeatBehavior en el código. Las animaciones son las mismas que en el ejemplo anterior, pero tienen establecido el atributo x:Name y RepeatBehavior se establece en el Start_Animation método en lugar de en 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();
}

Comentarios

Hay tres tipos de comportamientos repeatBehavior:

  • Intervalo de tiempo: especifica la duración activa de una escala de tiempo, posiblemente repitiendo la animación si timeline.Duration es más corta. Por ejemplo, una escala de tiempo con un valor timeline.Duration simple de 1 segundo y un valor RepeatBehavior.Duration de 2,5 segundos se ejecutarán durante 2,5 iteraciones y 2,5 segundos.
  • Recuento de iteraciones: especifica el número de veces que se reproduce la duración simple de una escala de tiempo . El recuento de iteraciones predeterminado es 1,0 y esto significa que la escala de tiempo está activa exactamente durante una de sus duraciones simples. Un recuento de 0,5 especifica que la escala de tiempo está activa durante la mitad de su duración simple, mientras que un recuento de 2 especifica que la escala de tiempo repite su duración simple dos veces. Para obtener más información, vea Recuento.
  • Forever: la escala de tiempo se repite indefinidamente.

Un RepeatBehavior solo debe contener valores distintos de cero para una de sus dos propiedades de datos posibles Count o Duration. Si RepeatBehaviorType es Count, el miembro Count de un RepeatBehavior es el valor pertinente. Si RepeatBehaviorType es Duration, el miembro Duration de repeatBehavior es el valor pertinente. Si RepeatBehaviorType es Forever, ni Count ni Duration son relevantes; el comportamiento de repetición es tal que la animación de destino se repetirá continuamente sin un límite.

Notas sobre la sintaxis XAML

No se puede declarar repeatBehavior como un objeto que se puede compartir en un ResourceDictionary.

Proyección y miembros de RepeatBehavior

Si usa un lenguaje Microsoft .NET (C# o Microsoft Visual Basic), RepeatBehavior tiene miembros que no son de datos disponibles y sus miembros de datos Count, Duration y Type se exponen como propiedades de lectura y escritura, no como campos.

Si usa extensiones de componentes de Visual C++ (C++/CX), RepeatBehavior tiene miembros que no son de datos disponibles y sus miembros de datos Count, Duration y Type se exponen como propiedades de solo lectura, no como campos.

Si está programando con C++ con la biblioteca de plantillas de Windows Runtime (WRL), solo existen los campos de miembro de datos Count, Duration y Type como miembros de RepeatBehavior, y no puede usar los métodos o propiedades de utilidad enumerados en la tabla de miembros. El código WRL puede tener acceso a métodos de utilidad similares que existen en la clase RepeatBehaviorHelper .

Campos

Count

Número de veces que se debe repetir una escala de tiempo .

Duration

Intervalo de tiempo para el que se debe repetir una escala de tiempo .

Type

Modo o tipo de comportamiento de repetición que representa esta instancia, como valor de la enumeración.

Se aplica a