2010-11-10 5 views
2

J'ai un problème avec la suppression de l'animation d'une propriété dans WPF. Lorsque les storyboards sont démarrés à l'aide d'un DataTrigger, je ne peux pas supprimer l'animation de la propriété comme dans d'autres cas. Peu importe ce que j'essaie ou où: l'OrientationProperty est verrouillé à la fin de l'animation. Vous pouvez le voir dans cet exemple car vous ne pouvez pas faire pivoter ScatterViewItem une fois le storyboard terminé.Comment supprimer une animation WPF définie dans un style?

C'est le XAML:

<s:SurfaceWindow x:Class="SurfaceApplication1.SurfaceWindow1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:s="http://schemas.microsoft.com/surface/2008" 
    x:Name="_this" 
    Title="SurfaceApplication1" 
    > 
    <s:SurfaceWindow.Resources> 
     <ImageBrush x:Key="WindowBackground" Stretch="None" Opacity="0.6" ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/> 

     <Storyboard x:Key="flipForward" Completed="FlipCompleted"> 
      <DoubleAnimation By="180" 
         FillBehavior="HoldEnd" 
         Duration="0:0:0.5" 
         Storyboard.TargetProperty="(s:ScatterViewItem.Orientation)" /> 
     </Storyboard> 

     <Storyboard x:Key="flipBackward" Completed="FlipCompleted"> 
      <DoubleAnimation By="-180" 
         FillBehavior="HoldEnd" 
         Duration="0:0:0.5" 
         Storyboard.TargetProperty="(s:ScatterViewItem.Orientation)" /> 
     </Storyboard> 
    </s:SurfaceWindow.Resources> 


    <Grid Background="{StaticResource WindowBackground}" > 
     <s:ScatterView> 
      <s:ScatterViewItem x:Name="_item" Orientation="0"> 
       <s:ScatterViewItem.Style> 
        <Style TargetType="{x:Type s:ScatterViewItem}" BasedOn="{StaticResource {x:Type s:ScatterViewItem}}"> 
         <Style.Triggers> 
          <DataTrigger Binding="{Binding ElementName=_button,Path=IsChecked}" Value="True"> 
           <DataTrigger.EnterActions> 
            <BeginStoryboard> 
             <StaticResource ResourceKey="flipForward" /> 
            </BeginStoryboard> 
           </DataTrigger.EnterActions> 
           <DataTrigger.ExitActions> 
            <BeginStoryboard> 
             <StaticResource ResourceKey="flipBackward" /> 
            </BeginStoryboard> 
           </DataTrigger.ExitActions> 
          </DataTrigger> 
         </Style.Triggers> 
        </Style> 
       </s:ScatterViewItem.Style> 

       <StackPanel> 
        <s:SurfaceToggleButton Margin="20" x:Name="_button">Click Me!</s:SurfaceToggleButton> 
       </StackPanel> 

      </s:ScatterViewItem> 
     </s:ScatterView> 
    </Grid> 
</s:SurfaceWindow> 

Et ceci est le code correspondant derrière:

private void FlipCompleted(object sender, EventArgs e) 
    { 
     _item.BeginAnimation(ScatterViewItem.OrientationProperty, null); // Doesn't work 
     ((sender as ClockGroup).Timeline as Storyboard).Remove(_item); // Doesn't work either 
     ((sender as ClockGroup).Timeline as Storyboard).Remove(); // Neither does this 
    } 

Est-ce que quelqu'un a un indice sur la façon de supprimer l'animation du OrientationProperty?

Répondre

1

Tout comme vous ajoutez un storyboard avec BeginStoryboard, vous pouvez également supprimer onve avec RemoveStoryboard en XAML. Je suis surpris cependant que BeginAnimation(ScatterViewItem.OrientationProperty, null); n'a pas fait le tour. À mon humble avis, il devrait avoir ...