Share via


Disabling Animations in WPF

Sometimes it's useful to turn off animations to improve performance, battery life, or simply because the flashiness gets in the way and becomes annoying. The obvious but incorrect solution is to simply not run the animation because sometimes the animation is critical for correctly positioning elements on the screen. For example, a thumbnail of an image may be animated to fill the screen when clicked on, but not running the animation means that the image never changes and remains a thumbnail, which is not what is wanted.

A solution to this problem is to simply set the duration of the animation to 0 seconds.

            Duration duration = new Duration(new TimeSpan(0, 0, 0, 0, 0)); 

An even better solution is to use Storyboard.SkipToFill(), which sets the animation clock to the end of the duration, plus it works for all animations within the storyboard.

            if (isAnimationDisabled)
            {
                // this is a FrameworkElement or FrameworkContentElement that contains the currentStoryboard
                currentStoryboard.SkipToFill(this);
            }

For more information on SkipToFill(), see https://msdn2.microsoft.com/en-us/library/system.windows.media.animation.storyboard.skiptofill.aspx
And for sample code on controlling a storyboard, see https://msdn2.microsoft.com/en-us/library/ms741997.aspx