Page 1 of 1

Storyboard Animation

Posted: 10 Jun 2014, 21:00
by kayrk
Is there a way to reset the storyboard to the beginning upon completion? I don't want it to reverse the animation back just simply set it back to where it was at the beginning instantly.

Re: Storyboard Animation

Posted: 12 Jun 2014, 21:15
by sfernandez
If you launch the storyboard as controllable, then you can stop it whenever you want, so animation is reset to the initial state.

To start the storyboard as controllable you have 2 options:

1) If using a BeginStoryboard trigger action, you have to set the BeginStoryboard.Name property:
<EventTrigger RoutedEvent="Button.Click" SourceName="buttonBegin">
    <BeginStoryboard Name="animSB" Storyboard="{StaticResource anim}"/>
</EventTrigger>
2) If you start the storyboard from code, remember to set the controllable flag to true:
animStoryboard.Begin(targetElement, targetElement, true);
Then you can stop the animation using a trigger action:
<EventTrigger RoutedEvent="Button.Click" SourceName="buttonStop">
    <StopStoryboard BeginStoryboardName="animSB" />
</EventTrigger>
Or from code:
animStoryboard.Stop(targetElement);