次の方法で共有


方法: アクティブ期間の終了に達したタイムラインの FillBehavior を指定する

この例では、非アクティブなアニメーション化されたプロパティ FillBehavior に対して Timeline を指定する方法を示します。

FillBehaviorTimeline プロパティは、アニメーション化されていない場合、つまり、Timeline が非アクティブであるが、親 Timeline がアクティブまたは保留期間内にある場合に、アニメーション化されたプロパティの値に対して何が起こるかを決定します。 たとえば、アニメーションが終了した後もアニメーション化されたプロパティは終了値のままですか、それともアニメーションが開始される前の値に戻りますか?

次の例では、DoubleAnimation を使用して、2 つの四角形の Width をアニメーション化します。 各四角形は、異なる Timeline オブジェクトを使用します。

1 つの Timeline には、FillBehaviorに設定された Stop があります。これにより、Timeline の終了時に四角形の幅がアニメーション化されていない値に戻ります。 もう 1 つの Timeline には FillBehaviorHoldEnd があり、これにより、Timeline の終了時に幅が終了値のままになります。

<Page 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <StackPanel Margin="20">
    <Border Background="#99FFFFFF">
      <TextBlock Margin="20">
              This example shows how the FillBehavior property determines how an animation behaves
              after it reaches the end of its duration.
      </TextBlock>
    </Border>
      
    <TextBlock>FillBehavior="Deactivate"</TextBlock>
    <Rectangle Name="deactiveAnimationRectangle" Width="20" Height="20" Fill="#AA3333FF" HorizontalAlignment="Left" >
      <Rectangle.Triggers>
        <EventTrigger RoutedEvent="Rectangle.Loaded">
          <BeginStoryboard>
            <Storyboard>

              <!-- The animated rectangle's width reverts back to its non-animated value
                   after the animation ends. -->
              <DoubleAnimation 
                Storyboard.TargetName="deactiveAnimationRectangle" 
                Storyboard.TargetProperty="Width" 
                From="100" To="400" Duration="0:0:2" FillBehavior="Stop" />
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Rectangle.Triggers>
    </Rectangle>

    <TextBlock Margin="0,20,0,0">FillBehavior="HoldEnd" </TextBlock>
    <Rectangle Name="holdEndAnimationRectangle" Width="20" Height="20" Fill="#AA3333FF" HorizontalAlignment="Left" >
      <Rectangle.Triggers>
        <EventTrigger RoutedEvent="Rectangle.Loaded">
          <BeginStoryboard>
            <Storyboard>

              <!-- The animated rectangle's width remains at its end value after the 
                   animation ends. -->
              <DoubleAnimation Storyboard.TargetName="holdEndAnimationRectangle" 
                Storyboard.TargetProperty="Width"  
                From="100" To="400" Duration="0:0:2" FillBehavior="HoldEnd" />
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Rectangle.Triggers>
    </Rectangle>
  </StackPanel>
</Page>

完全なサンプルについては、「アニメーションサンプルギャラリー参照してください。

こちらも参照ください