While scaling a panel using a scale transform the application needs to reset the panel back to its original size. For this purpose a reset button starts a double animation that animates the scale transform from it's start value to 1 which means the panel will have it original value.
Visually the panel is scaled back to orignal size, but after the animation finishes the storyboard's complete event is raised twice, and once both of those events has been raised the value of the scale transform is set back to the value that it had before the animation.
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
if (!isReseting)
{
isReseting = true;
this.doubleAnimation = new DoubleAnimation(1, new Duration(new TimeSpan(0,0,0, 1)), FillBehavior.Stop);
this.resetStoryboard = new Storyboard();
resetStoryboard.Children.Add(doubleAnimation);
Storyboard.SetTarget(doubleAnimation, zoomSliderControl);
Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath(RangeBase.ValueProperty));
resetStoryboard.RepeatBehavior = new RepeatBehavior(1);
resetStoryboard.Completed += new EventHandler(ResetStoryboardCompleted);
resetStoryboard.Begin();
}
}
private void ResetStoryboardCompleted(object sender, EventArgs e)
{
if (resetStoryboard != null)
{
//resetStoryboard.Stop(zoomSliderControl);
//resetStoryboard.Remove(zoomSliderControl);
}
resetStoryboard = null;
doubleAnimation = null;
isReseting = false;
}
For example, if the value of the Slider control (named zoomSliderControl) is 1.5 before the animation, then it animates back to 1 as expected, but once the completed event of resetStoryBoard has been raised twice it is set back to 1.5 again.
I've tried debugging the application, and it's right after the second ResetStoryboardCompleted method has termined that the value is set to its original value so I'm guessing that I haven't configured the storyboard or animation correctly.