/// <summary> /// Animates the window's height /// </summary> /// <param name="window">The window to animate</param> /// <param name="height">The height to animate the window to</param> /// <param name="duration">The duration for the animation</param> /// <param name="callback">An optional callback to be executed when the animation finishes</param> private void animateWindowHeight(Window window, double height, double duration, Action callback = null) { window.BeginInit(); window.Dispatcher.BeginInvoke((Action)(() => { DoubleAnimation windowAnimation = new DoubleAnimation(); windowAnimation.Duration = new Duration(TimeSpan.FromSeconds(duration)); windowAnimation.From = window.Height; windowAnimation.To = height; windowAnimation.FillBehavior = FillBehavior.HoldEnd; //If a callback is passed, execute it using a lambda expression if (callback != null) { windowAnimation.Completed += (s, e) => callback(); } window.BeginAnimation(Window.HeightProperty, windowAnimation); }), null); window.EndInit(); }