public static void Unblur(this FrameworkElement frameworkElement, FrameworkElement parent, TimeSpan duration, Action completed = null) { if (!(frameworkElement.Effect is BlurEffect blurEffect)) return; string key = "Blur" + frameworkElement.GetHashCode(); if (frameworkElement.Tag is StoryboardTag tag) { tag.Item1.Stop(); parent.Resources.Remove(key); } float from = blurEffect.Radius; DoubleAnimation animation = new DoubleAnimation(); animation.Duration = new Duration(duration); animation.AutoReverse = false; animation.FillBehavior = FillBehavior.Stop; Storyboard storyboard = new Storyboard(); storyboard.AutoReverse = false; storyboard.Duration = animation.Duration; storyboard.FillBehavior = FillBehavior.Stop; storyboard.Children.Add(animation); parent.Resources.Add(key, storyboard); frameworkElement.Tag = new StoryboardTag(storyboard, 1); Storyboard.SetTarget(animation, frameworkElement); Storyboard.SetTargetProperty(animation, new PropertyPath("Effect.Radius")); animation.From = from; animation.To = 0; storyboard.Completed += (sender2, e2) => { parent.Resources.Remove(key); frameworkElement.Tag = null; blurEffect.Radius = 0; frameworkElement.Effect = null; completed?.Invoke(); }; storyboard.Begin(); } public static void Blur(this FrameworkElement frameworkElement, FrameworkElement parent, float radius, TimeSpan duration, Action completed = null) { if (!(frameworkElement.Effect is BlurEffect blurEffect)) { blurEffect = new BlurEffect(); frameworkElement.Effect = blurEffect; } string key = "Blur" + frameworkElement.GetHashCode(); if (frameworkElement.Tag is StoryboardTag tag) { tag.Item1.Stop(); parent.Resources.Remove(key); } float from = blurEffect.Radius; DoubleAnimation animation = new DoubleAnimation(); animation.Duration = new Duration(duration); animation.AutoReverse = false; animation.FillBehavior = FillBehavior.Stop; Storyboard storyboard = new Storyboard(); storyboard.AutoReverse = false; storyboard.Duration = animation.Duration; storyboard.FillBehavior = FillBehavior.Stop; storyboard.Children.Add(animation); parent.Resources.Add(key, storyboard); frameworkElement.Tag = new StoryboardTag(storyboard, 1); Storyboard.SetTarget(animation, frameworkElement); Storyboard.SetTargetProperty(animation, new PropertyPath("Effect.Radius")); animation.From = from; animation.To = radius; storyboard.Completed += (sender2, e2) => { parent.Resources.Remove(key); frameworkElement.Tag = null; blurEffect.Radius = radius; completed?.Invoke(); }; storyboard.Begin(); }