diff --git a/Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml.cs b/Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml.cs index c115374..25201ec 100644 --- a/Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml.cs +++ b/Enterwell.Clients.Wpf.Notifications.Sample/MainWindow.xaml.cs @@ -17,8 +17,12 @@ public MainWindow() { this.InitializeComponent(); this.DataContext = this; + Manager.OnMessageDismissed += Manager_OnMessageDismissed; } + private void Manager_OnMessageDismissed(object sender, NotificationMessageManagerEventArgs args) + { + } private void ButtonBaseErrorOnClick(object sender, RoutedEventArgs e) { diff --git a/Enterwell.Clients.Wpf.Notifications/Controls/NotificationMessageContainer.cs b/Enterwell.Clients.Wpf.Notifications/Controls/NotificationMessageContainer.cs index 8fe5606..1d1d40b 100644 --- a/Enterwell.Clients.Wpf.Notifications/Controls/NotificationMessageContainer.cs +++ b/Enterwell.Clients.Wpf.Notifications/Controls/NotificationMessageContainer.cs @@ -38,10 +38,10 @@ private static void ManagerPropertyChangedCallback(DependencyObject dependencyOb { if (!(dependencyObject is NotificationMessageContainer @this)) throw new NullReferenceException("Dependency object is not of valid type " + nameof(NotificationMessageContainer)); - + if (dependencyPropertyChangedEventArgs.OldValue is INotificationMessageManager oldManager) @this.DetachManagerEvents(oldManager); - + if (dependencyPropertyChangedEventArgs.NewValue is INotificationMessageManager newManager) @this.AttachManagerEvents(newManager); } @@ -78,26 +78,7 @@ private void ManagerOnOnMessageDismissed(object sender, NotificationMessageManag throw new InvalidOperationException( "Can't use both ItemsSource and Items collection at the same time."); - if (args.Message is INotificationAnimation animatableMessage) - { - var animation = animatableMessage.AnimationOut; - if (animation != null && - animatableMessage.Animates && - animatableMessage.AnimatableElement != null && - animatableMessage.AnimationOutDependencyProperty != null) - { - animation.Completed += (s, a) => this.RemoveMessage(args.Message); - animatableMessage.AnimatableElement.BeginAnimation(animatableMessage.AnimationOutDependencyProperty, animation); - } - else - { - this.RemoveMessage(args.Message); - } - } - else - { - this.RemoveMessage(args.Message); - } + this.RemoveMessage(args.Message); } private void RemoveMessage(INotificationMessage message) diff --git a/Enterwell.Clients.Wpf.Notifications/NotificationMessageBuilderLinq.cs b/Enterwell.Clients.Wpf.Notifications/NotificationMessageBuilderLinq.cs index a34fc58..008b055 100644 --- a/Enterwell.Clients.Wpf.Notifications/NotificationMessageBuilderLinq.cs +++ b/Enterwell.Clients.Wpf.Notifications/NotificationMessageBuilderLinq.cs @@ -231,28 +231,7 @@ private static Action DismissBefore( { return call => { - if (builder.Message is INotificationAnimation animatableMessage) - { - var animation = animatableMessage.AnimationOut; - if (animation != null && - animatableMessage.Animates && - animatableMessage.AnimatableElement != null && - animatableMessage.AnimationOutDependencyProperty != null) - { - animation.Completed += (s, a) => - { - builder.Manager.Dismiss(builder.Message); - }; - } - else - { - builder.Manager.Dismiss(builder.Message); - } - } - else - { - builder.Manager.Dismiss(builder.Message); - } + builder.Manager.Dismiss(builder.Message); callback?.Invoke(builder.Message); }; } @@ -272,28 +251,7 @@ private static Action DismissBefore( { return button => { - if (builder.Message is INotificationAnimation animatableMessage) - { - var animation = animatableMessage.AnimationOut; - if (animation != null && - animatableMessage.Animates && - animatableMessage.AnimatableElement != null && - animatableMessage.AnimationOutDependencyProperty != null) - { - animation.Completed += (s, a) => - { - builder.Manager.Dismiss(builder.Message); - }; - } - else - { - builder.Manager.Dismiss(builder.Message); - } - } - else - { - builder.Manager.Dismiss(builder.Message); - } + builder.Manager.Dismiss(builder.Message); callback?.Invoke(button); }; } @@ -360,11 +318,11 @@ public static NotificationMessageBuilder WithAdditionalContent( default: { break; } } - + return builder; } - + /// /// Sets the foreground brush. /// diff --git a/Enterwell.Clients.Wpf.Notifications/NotificationMessageManager.cs b/Enterwell.Clients.Wpf.Notifications/NotificationMessageManager.cs index 7c40fd6..593a036 100644 --- a/Enterwell.Clients.Wpf.Notifications/NotificationMessageManager.cs +++ b/Enterwell.Clients.Wpf.Notifications/NotificationMessageManager.cs @@ -66,7 +66,29 @@ public void Dismiss(INotificationMessage message) this.queuedMessages.Remove(message); - this.TriggerMessageDismissed(message); + if (message is INotificationAnimation animatableMessage) + { + var animation = animatableMessage.AnimationOut; + if (animation != null && + animatableMessage.Animates && + animatableMessage.AnimatableElement != null && + animatableMessage.AnimationOutDependencyProperty != null) + { + animation.Completed += (s, a) => + { + this.TriggerMessageDismissed(message); + }; + animatableMessage.AnimatableElement.BeginAnimation(animatableMessage.AnimationOutDependencyProperty, animation); + } + else + { + this.TriggerMessageDismissed(message); + } + } + else + { + this.TriggerMessageDismissed(message); + } } ///