RepeatBehavior 構造体

定義

タイムラインが単純な期間を繰り返す方法について説明します。

/// [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"/>
継承
RepeatBehavior
属性

Windows の要件

デバイス ファミリ
Windows 10 (10.0.10240.0 で導入)
API contract
Windows.Foundation.UniversalApiContract (v1.0 で導入)

この例では、アニメーションの RepeatBehavior を設定するさまざまな方法と、これらの設定がアニメーションに与える影響を示します。

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

この例では、コードで RepeatBehavior を設定する方法を示します。 アニメーションは前の例と同じですが、 x:Name 属性が設定されており、RepeatBehavior は XAML ではなく メソッドで Start_Animation 設定されています。

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

注釈

RepeatBehavior の動作には、次の 3 種類があります。

  • 期間: タイムラインのアクティブな期間を指定 しますTimeline.Duration が短い場合はアニメーションを繰り返す可能性があります。 たとえば、単純な Timeline.Duration 値が 1 秒で RepeatBehavior.Duration 値が 2.5 秒のタイムラインは、2.5 回の繰り返しと 2.5 秒で実行されます。
  • 反復回数: タイムライン の単純な再生時間の回数を指定します。 既定の反復回数は 1.0 で、これは タイムライン が単純な期間の 1 つだけアクティブであることを意味します。 カウントが 0.5 の場合は、タイムラインが単純な期間の半分でアクティブであることを指定します。一方、カウント 2 は、タイムラインがその単純な期間を 2 回繰り返すことに指定します。 詳細については、「 カウント」を参照してください。
  • 永遠: タイムライン は無期限に繰り返されます。

RepeatBehavior には、使用可能な 2 つのデータ プロパティ Count または Duration の 1 つに対して 0 以外の値のみを含める必要があります。 RepeatBehaviorTypeCount の場合、RepeatBehavior の Count メンバーが関連する値になります。 RepeatBehaviorTypeDuration の場合、RepeatBehavior の Duration メンバーが関連する値になります。 RepeatBehaviorTypeForever の場合、CountDuration も関連しません。繰り返し動作は、対象のアニメーションが制限なしで継続的に繰り返されるようにします。

XAML 構文に関する注意事項

ResourceDictionary で RepeatBehavior を共有可能なオブジェクトとして宣言することはできません。

RepeatBehavior のプロジェクションとメンバー

Microsoft .NET 言語 (C# または Microsoft Visual Basic) を使用している場合、RepeatBehavior にはデータ以外のメンバーが使用でき、そのデータ メンバー CountDurationType はフィールドではなく読み取り/書き込みプロパティとして公開されます。

Visual C++ コンポーネント拡張機能 (C++/CX) を使用している場合、RepeatBehavior にはデータ以外のメンバーが使用でき、そのデータ メンバー CountDurationType はフィールドではなく読み取り専用プロパティとして公開されます。

Windows ランタイム テンプレート ライブラリ (WRL) を使用して C++ を使用してプログラミングする場合、データ メンバー フィールド CountDurationType のみが RepeatBehavior のメンバーとして存在し、メンバー テーブルに一覧表示されているユーティリティ メソッドまたはプロパティを使用することはできません。 WRL コードは、 RepeatBehaviorHelper クラスに存在する同様のユーティリティ メソッドにアクセスできます。

フィールド

Count

タイムラインを繰り返す回数。

Duration

タイムラインを繰り返す期間。

Type

列挙体の値として、このインスタンスが表す繰り返し動作のモードまたは種類。

適用対象