private void AnimateBackdrop(bool show) { if (Container == null) { throw new NotImplementedException($"'{nameof(Container)}' must be implemented"); } if (UseBackdrop && Backdrop == null) { throw new NotImplementedException($"'{nameof(Backdrop)}' must be implemented when '{nameof(UseBackdrop)}' is true"); } var opacity = show ? 0.6 : 0; if (show || Backdrop.Visibility == Visibility.Hidden) { Backdrop.Visibility = Visibility.Visible; } var backdropAnimation = new DoubleAnimation(Backdrop.Opacity, opacity, TimeSpan.FromMilliseconds(200)); if (!show) { backdropAnimation.Completed += (sender, args) => Backdrop.Visibility = Visibility.Hidden; } Backdrop.BeginAnimation(UIElement.OpacityProperty, backdropAnimation); }