다음을 통해 공유


방법: 활성 기간이 끝난 Timeline의 FillBehavior 지정

이 예제는 애니메이션 속성의 비활성 Timeline에 대해 FillBehavior를 지정하는 방법을 보여 줍니다.

예제

TimelineFillBehavior 속성은 애니메이션 효과가 적용되지 않을 때, 즉 Timeline이 비활성화이지만 부모인 Timeline이 활성 또는 보류 기간 내에 있을 때 애니메이션 속성의 값에 무슨 일이 일어나는지를 결정합니다. 예를 들어 애니메이션이 종료된 후 애니메이션 속성이 끝 값에 유지되거나 애니메이션이 시작되기 전의 값으로 되돌려지나요?

다음 예제에서는 DoubleAnimation을 사용하여 두 사각형의 Width에 애니메이션 효과를 적용합니다. 각 사각형은 서로 다른 Timeline 개체를 사용합니다.

TimelineFillBehaviorStop으로 설정되어 있으며, 이로 인해 Timeline이 종료되면 사각형의 너비가 애니메이션이 적용되지 않은 값으로 되돌려집니다. 다른 TimelineFillBehaviorHoldEnd이며, 이로 인해 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>

전체 샘플은 애니메이션 예제 갤러리를 참조하세요.

참고 항목