How to prevent animation interruption [WPF]

For example, I have an animation that starts when I click.

The problem is that if you keep clicking the animation, it restarts.

I want to guarantee that the animation will always be executed until completion.

Ideas?

+4
source share
2 answers

One trick I found is not to include From in my animations . That way, values ​​will always start with any value that the property you are animating has right now. This means that if you restart the animation, it will not return the reset property to its starting value and instead will look as if it continues the original animation.

+2
source

Still not the exact answer you are looking for, but this solved the problem that I contacted with the MouseDown trigger, which launched a new animation on top of the one that was still running:

<BeginStoryboard> <Storyboard AutoReverse="True"> <ColorAnimation Storyboard.TargetProperty="(Label.Foreground).(SolidColorBrush.Color)" To="Red" Duration="0:0:1"/> </Storyboard> 

The problem with this animation is that when it starts again before it finishes, the auto-reverse function turns it into the red color that it reached before it was run a second time, and not the original color that it had before the first animation has begun.

In my case, this was easily resolved this way:

 <BeginStoryBoard HandOffBehavior="Compose"> 
0
source

All Articles