Compartir a través de


Cómo: Especificar el comportamiento de relleno de una escala de tiempo que ha llegado al final de su período de actividad

En este ejemplo se muestra cómo especificar FillBehavior para el elemento Timeline inactivo de una propiedad animada.

Ejemplo

La propiedad FillBehavior de Timeline determina lo que le ocurre al valor de una propiedad animada cuando no se está animando, es decir, cuando el elemento Timeline está inactivo pero su elemento Timeline primario está dentro de su período de actividad o de espera. Por ejemplo, ¿una propiedad animada permanece en su valor final después de que la animación finaliza o retoma el valor que tenía antes de que la animación se iniciara?

En el ejemplo siguiente se usa DoubleAnimation para animar la propiedad Width de dos rectángulos. Cada rectángulo usa un objeto Timeline diferente.

Un objeto Timeline tiene una propiedad FillBehavior que está establecida en Stop, lo que hace que el ancho del rectángulo recupere su valor no animado cuando Timeline finaliza. El otro objeto Timeline tiene la propiedad FillBehavior establecida en HoldEnd, lo que hace que el ancho permanezca en su valor final cuando Timeline finaliza.

<Page 
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="https://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>

Para tener el ejemplo completo, vea Animation Example Gallery.

Vea también

Referencia

DoubleAnimation

Width

Timeline

FillBehavior

Stop

HoldEnd

Conceptos

Información general sobre animaciones

Otros recursos

Animación y temporización

Temas "Cómo..." de animación y control de tiempo