From cdf0d097809410b1ea56415dec41648326652c8c Mon Sep 17 00:00:00 2001 From: Vincent Gromfeld Date: Mon, 29 Jun 2020 14:17:47 +0200 Subject: [PATCH 1/5] remove locks --- .../InAppNotificationXaml.bind | 6 +- .../InAppNotification.Constants.cs | 5 + .../InAppNotification.Events.cs | 60 ++--- .../InAppNotification/InAppNotification.cs | 223 +++++++++--------- .../Styles/MSEdgeNotificationStyle.xaml | 204 +++++++++------- .../Styles/VSCodeNotificationStyle.xaml | 210 ++++++++++------- 6 files changed, 396 insertions(+), 312 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind index 0b5afac336d..d3be2911f64 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind @@ -153,7 +153,8 @@ - - private const string DismissButtonPart = "PART_DismissButton"; + + /// + /// Key of the UI Element that will display the notification content. + /// + private const string ContentPresenterPart = "PART_Presenter"; } } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.Events.cs index 107f55a0342..32282d70de9 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.Events.cs @@ -35,6 +35,19 @@ public partial class InAppNotification /// public event InAppNotificationClosedEventHandler Closed; + private static void AutomateTextNotification(AutomationPeer peer, string message) + { + if (peer != null) + { + peer.SetFocus(); + peer.RaiseNotificationEvent( + AutomationNotificationKind.Other, + AutomationNotificationProcessing.ImportantMostRecent, + StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_Events_NewNotificationMessage", "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/Microsoft.Toolkit.Uwp.UI.Controls/Resources") + message, + Guid.NewGuid().ToString()); + } + } + private void DismissButton_Click(object sender, RoutedEventArgs e) { Dismiss(InAppNotificationDismissKind.User); @@ -45,44 +58,37 @@ private void DismissTimer_Tick(object sender, object e) Dismiss(InAppNotificationDismissKind.Timeout); } - private void OpenAnimationTimer_Tick(object sender, object e) + private void OnCurrentStateChanged(object sender, VisualStateChangedEventArgs e) { - lock (_openAnimationTimer) + switch (e.NewState.Name) { - _openAnimationTimer.Stop(); - Opened?.Invoke(this, EventArgs.Empty); - SetValue(AutomationProperties.NameProperty, StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_NameProperty", "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/Microsoft.Toolkit.Uwp.UI.Controls/Resources")); - if (ContentTemplateRoot != null) - { - var peer = FrameworkElementAutomationPeer.CreatePeerForElement(ContentTemplateRoot); - if (Content?.GetType() == typeof(string)) - { - AutomateTextNotification(peer, Content.ToString()); - } - } + case StateContentVisible: + OnNotificationVisible(); + break; + case StateContentCollapsed: + OnNotificationCollapsed(); + break; } } - private void AutomateTextNotification(AutomationPeer peer, string message) + private void OnNotificationVisible() { - if (peer != null) + Opened?.Invoke(this, EventArgs.Empty); + SetValue(AutomationProperties.NameProperty, StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_NameProperty", "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/Microsoft.Toolkit.Uwp.UI.Controls/Resources")); + if (ContentTemplateRoot != null) { - peer.SetFocus(); - peer.RaiseNotificationEvent( - AutomationNotificationKind.Other, - AutomationNotificationProcessing.ImportantMostRecent, - StringExtensions.GetLocalized("WindowsCommunityToolkit_InAppNotification_Events_NewNotificationMessage", "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/Microsoft.Toolkit.Uwp.UI.Controls/Resources") + message, - Guid.NewGuid().ToString()); + var peer = FrameworkElementAutomationPeer.CreatePeerForElement(ContentTemplateRoot); + if (Content?.GetType() == typeof(string)) + { + AutomateTextNotification(peer, Content.ToString()); + } } } - private void ClosingAnimationTimer_Tick(object sender, object e) + private void OnNotificationCollapsed() { - lock (_closingAnimationTimer) - { - _closingAnimationTimer.Stop(); - Closed?.Invoke(this, new InAppNotificationClosedEventArgs(_lastDismissKind)); - } + Closed?.Invoke(this, new InAppNotificationClosedEventArgs(_lastDismissKind)); + Visibility = Visibility.Collapsed; } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs index 222c43e8723..83459339724 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs @@ -16,14 +16,14 @@ namespace Microsoft.Toolkit.Uwp.UI.Controls [TemplateVisualState(Name = StateContentVisible, GroupName = GroupContent)] [TemplateVisualState(Name = StateContentCollapsed, GroupName = GroupContent)] [TemplatePart(Name = DismissButtonPart, Type = typeof(Button))] + [TemplatePart(Name = ContentPresenterPart, Type = typeof(ContentPresenter))] public partial class InAppNotification : ContentControl { private InAppNotificationDismissKind _lastDismissKind; - private DispatcherTimer _openAnimationTimer = new DispatcherTimer(); - private DispatcherTimer _closingAnimationTimer = new DispatcherTimer(); private DispatcherTimer _dismissTimer = new DispatcherTimer(); private Button _dismissButton; private VisualStateGroup _visualStateGroup; + private ContentPresenter _contentProvider; private List _stackedNotificationOptions = new List(); /// @@ -34,20 +34,26 @@ public InAppNotification() DefaultStyleKey = typeof(InAppNotification); _dismissTimer.Tick += DismissTimer_Tick; - _openAnimationTimer.Tick += OpenAnimationTimer_Tick; - _closingAnimationTimer.Tick += ClosingAnimationTimer_Tick; } /// protected override void OnApplyTemplate() { + base.OnApplyTemplate(); + if (_dismissButton != null) { _dismissButton.Click -= DismissButton_Click; } + if (_visualStateGroup != null) + { + _visualStateGroup.CurrentStateChanged -= OnCurrentStateChanged; + } + _dismissButton = (Button)GetTemplateChild(DismissButtonPart); _visualStateGroup = (VisualStateGroup)GetTemplateChild(GroupContent); + _contentProvider = (ContentPresenter)GetTemplateChild(ContentPresenterPart); if (_dismissButton != null) { @@ -55,16 +61,17 @@ protected override void OnApplyTemplate() _dismissButton.Click += DismissButton_Click; } - if (Visibility == Visibility.Visible) + if (_visualStateGroup != null) { - VisualStateManager.GoToState(this, StateContentVisible, true); + _visualStateGroup.CurrentStateChanged += OnCurrentStateChanged; } - else + + var firstNotification = _stackedNotificationOptions.FirstOrDefault(); + if (firstNotification != null) { - VisualStateManager.GoToState(this, StateContentCollapsed, true); + UpdateContent(firstNotification); + VisualStateManager.GoToState(this, StateContentVisible, true); } - - base.OnApplyTemplate(); } /// @@ -73,34 +80,24 @@ protected override void OnApplyTemplate() /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) public void Show(int duration = 0) { - lock (_openAnimationTimer) - lock (_closingAnimationTimer) - lock (_dismissTimer) - { - _openAnimationTimer.Stop(); - _closingAnimationTimer.Stop(); - _dismissTimer.Stop(); - - var eventArgs = new InAppNotificationOpeningEventArgs(); - Opening?.Invoke(this, eventArgs); - - if (eventArgs.Cancel) - { - return; - } - - Visibility = Visibility.Visible; - VisualStateManager.GoToState(this, StateContentVisible, true); - - _openAnimationTimer.Interval = AnimationDuration; - _openAnimationTimer.Start(); - - if (duration > 0) - { - _dismissTimer.Interval = TimeSpan.FromMilliseconds(duration); - _dismissTimer.Start(); - } - } + _dismissTimer.Stop(); + + var eventArgs = new InAppNotificationOpeningEventArgs(); + Opening?.Invoke(this, eventArgs); + + if (eventArgs.Cancel) + { + return; + } + + // We keep our current content + var notificationOptions = new NotificationOptions + { + Duration = duration, + Content = Content + }; + + Show(notificationOptions); } /// @@ -162,64 +159,48 @@ public void Dismiss() /// Kind of action that triggered dismiss event private void Dismiss(InAppNotificationDismissKind dismissKind) { - lock (_openAnimationTimer) - lock (_closingAnimationTimer) - lock (_dismissTimer) - { - if (Visibility == Visibility.Visible) - { - _dismissTimer.Stop(); - - // Continue to display notification if on remaining stacked notification - if (_stackedNotificationOptions.Any()) - { - _stackedNotificationOptions.RemoveAt(0); - - if (_stackedNotificationOptions.Any()) - { - var notificationOptions = _stackedNotificationOptions[0]; - - UpdateContent(notificationOptions); - - if (notificationOptions.Duration > 0) - { - _dismissTimer.Interval = TimeSpan.FromMilliseconds(notificationOptions.Duration); - _dismissTimer.Start(); - } - - return; - } - } - - _openAnimationTimer.Stop(); - _closingAnimationTimer.Stop(); - - var closingEventArgs = new InAppNotificationClosingEventArgs(dismissKind); - Closing?.Invoke(this, closingEventArgs); - - if (closingEventArgs.Cancel) - { - return; - } - - VisualStateManager.GoToState(this, StateContentCollapsed, true); - - _lastDismissKind = dismissKind; - - _closingAnimationTimer.Interval = AnimationDuration; - _closingAnimationTimer.Start(); - } - } - } + if (_stackedNotificationOptions.Count == 0) + { + // There is nothing to dismiss. + return; + } - /// - /// Informs if the notification should be displayed immediately (based on the StackMode) - /// - /// True if notification should be displayed immediately - private bool ShouldDisplayImmediately() - { - return StackMode != StackMode.QueueBehind || - (StackMode == StackMode.QueueBehind && _stackedNotificationOptions.Count == 0); + _dismissTimer.Stop(); + + // Continue to display notification if on remaining stacked notification + _stackedNotificationOptions.RemoveAt(0); + if (_stackedNotificationOptions.Any()) + { + var notificationOptions = _stackedNotificationOptions[0]; + + UpdateContent(notificationOptions); + + if (notificationOptions.Duration > 0) + { + _dismissTimer.Interval = TimeSpan.FromMilliseconds(notificationOptions.Duration); + _dismissTimer.Start(); + } + + return; + } + + var closingEventArgs = new InAppNotificationClosingEventArgs(dismissKind); + Closing?.Invoke(this, closingEventArgs); + + if (closingEventArgs.Cancel) + { + return; + } + + var result = VisualStateManager.GoToState(this, StateContentCollapsed, true); + if (!result) + { + // The state transition cannot be executed. + // It means that the control's template hasn't been applied or that it doesn't contain the state. + Visibility = Visibility.Collapsed; + } + + _lastDismissKind = dismissKind; } /// @@ -228,19 +209,25 @@ private bool ShouldDisplayImmediately() /// Information about the notification to display private void UpdateContent(NotificationOptions notificationOptions) { + if (_contentProvider is null) + { + // The control template has not been applied yet. + return; + } + switch (notificationOptions.Content) { case string text: - ContentTemplate = null; - Content = text; + _contentProvider.ContentTemplate = null; + _contentProvider.Content = text; break; case UIElement element: - ContentTemplate = null; - Content = element; + _contentProvider.ContentTemplate = null; + _contentProvider.Content = element; break; case DataTemplate dataTemplate: - ContentTemplate = dataTemplate; - Content = null; + _contentProvider.ContentTemplate = dataTemplate; + _contentProvider.Content = null; break; } } @@ -251,22 +238,36 @@ private void UpdateContent(NotificationOptions notificationOptions) /// Information about the notification to display private void Show(NotificationOptions notificationOptions) { - bool shouldDisplayImmediately = ShouldDisplayImmediately(); - - if (StackMode == StackMode.QueueBehind) - { - _stackedNotificationOptions.Add(notificationOptions); - } - - if (StackMode == StackMode.StackInFront) + var shouldDisplayImmediately = true; + switch (StackMode) { - _stackedNotificationOptions.Insert(0, notificationOptions); + case StackMode.Replace: + _stackedNotificationOptions.Clear(); + _stackedNotificationOptions.Add(notificationOptions); + break; + case StackMode.StackInFront: + _stackedNotificationOptions.Insert(0, notificationOptions); + break; + case StackMode.QueueBehind: + _stackedNotificationOptions.Add(notificationOptions); + shouldDisplayImmediately = _stackedNotificationOptions.Count == 1; + break; + default: + break; } if (shouldDisplayImmediately) { UpdateContent(notificationOptions); - Show(notificationOptions.Duration); + + Visibility = Visibility.Visible; + VisualStateManager.GoToState(this, StateContentVisible, true); + + if (notificationOptions.Duration > 0) + { + _dismissTimer.Interval = TimeSpan.FromMilliseconds(notificationOptions.Duration); + _dismissTimer.Start(); + } } } } diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml index 63e376f0b62..106dd41c833 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml @@ -1,26 +1,34 @@ - + - + - - - + + + - + - - - + + + - - + + + + + + + + + + + + + + + - - + - - - + + - - - + + - - - + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - + + - - - + + - - - + + - - - + + - - - - - - - - - - - - - - - - - From 3916d5a62bd9cb362db97050baaf4004a4f3a1ef Mon Sep 17 00:00:00 2001 From: Vincent Gromfeld Date: Mon, 29 Jun 2020 16:43:42 +0200 Subject: [PATCH 2/5] add show(object) --- .../InAppNotificationPage.xaml.cs | 14 +++++++++-- .../InAppNotificationXaml.bind | 12 +++++++++- .../InAppNotification/InAppNotification.cs | 24 +++++++++++++++++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationPage.xaml.cs b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationPage.xaml.cs index 6a5f814e15a..cb35082fd6f 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationPage.xaml.cs +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationPage.xaml.cs @@ -2,10 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Windows.Input; using Microsoft.Toolkit.Uwp.UI.Controls; using Microsoft.Toolkit.Uwp.UI.Extensions; +using System; +using System.Collections.Generic; +using System.Windows.Input; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; @@ -57,6 +58,15 @@ private void Load() _exampleInAppNotification?.Show(GetRandomText(), NotificationDuration); }); + SampleController.Current.RegisterNewCommand("Show notification with object", (sender, args) => + { + _exampleVSCodeInAppNotification?.Dismiss(); + SetDefaultControlTemplate(); + + var random = new Random(); + _exampleInAppNotification?.Show(new KeyValuePair(random.Next(1, 10), GetRandomText()), NotificationDuration); + }); + SampleController.Current.RegisterNewCommand("Show notification with buttons (without DataTemplate)", (sender, args) => { _exampleVSCodeInAppNotification?.Dismiss(); diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind index d3be2911f64..812d93e65cd 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationXaml.bind @@ -378,7 +378,17 @@ AnimationDuration="@[AnimationDuration:TimeSpan:100:0-5000]" VerticalOffset="@[VerticalOffset:DoubleSlider:100.0:-200.0-200.0]" HorizontalOffset="@[HorizontalOffset:DoubleSlider:0.0:-200.0-200.0]" - StackMode="@[StackMode:Enum:StackMode.Replace]" /> + StackMode="@[StackMode:Enum:StackMode.Replace]"> + + + + + + + + + + - /// Show notification using the current template + /// Show notification using the current content. /// /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) public void Show(int duration = 0) @@ -131,7 +131,7 @@ public void Show(UIElement element, int duration = 0) } /// - /// Show notification using DataTemplate as the content of the notification + /// Show notification using as the content of the notification /// /// DataTemplate used as the content of the notification /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) @@ -145,6 +145,22 @@ public void Show(DataTemplate dataTemplate, int duration = 0) Show(notificationOptions); } + /// + /// Show notification using as the content of the notification. + /// The will be displayed with the current . + /// + /// The content of the notification + /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) + public void Show(object content, int duration = 0) + { + var notificationOptions = new NotificationOptions + { + Duration = duration, + Content = content + }; + Show(notificationOptions); + } + /// /// Dismiss the notification /// @@ -229,6 +245,10 @@ private void UpdateContent(NotificationOptions notificationOptions) _contentProvider.ContentTemplate = dataTemplate; _contentProvider.Content = null; break; + case object content: + _contentProvider.ContentTemplate = ContentTemplate; + _contentProvider.Content = content; + break; } } From 7acb5867e593e5463738e5bc9eb0643b071432f0 Mon Sep 17 00:00:00 2001 From: Vincent Gromfeld Date: Thu, 2 Jul 2020 09:33:37 +0200 Subject: [PATCH 3/5] Update code sample --- .../InAppNotification/InAppNotificationCode.bind | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationCode.bind b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationCode.bind index 5b656636a0b..b151f91a4fe 100644 --- a/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationCode.bind +++ b/Microsoft.Toolkit.Uwp.SampleApp/SamplePages/InAppNotification/InAppNotificationCode.bind @@ -46,6 +46,14 @@ if (isTemplatePresent && inAppNotificationWithButtonsTemplate is DataTemplate) ExampleInAppNotification.Show(inAppNotificationWithButtonsTemplate as DataTemplate); } +// Show notification using an object + + +var notificationData = new MyNotificationData("Title", "Message"); +ExampleInAppNotification.Show(notificationData, duration: 2000); + // Dismiss notification ExampleInAppNotification.Dismiss(); @@ -53,14 +61,14 @@ ExampleInAppNotification.Dismiss(); private void YesButton_Click(object sender, RoutedEventArgs e) { - // TODO : Do something when user accepted + // TODO : Do something when user accepted ExampleInAppNotification.Dismiss(); } private void NoButton_Click(object sender, RoutedEventArgs e) { - // TODO : Do something when user refused + // TODO : Do something when user refused ExampleInAppNotification.Dismiss(); } \ No newline at end of file From 9658240639823b1e76e17a1b388bdaaf4d21fad5 Mon Sep 17 00:00:00 2001 From: Vincent Gromfeld Date: Thu, 2 Jul 2020 09:38:22 +0200 Subject: [PATCH 4/5] fix xaml style --- .../InAppNotification/InAppNotification.xaml | 20 +++++++------ .../Styles/MSEdgeNotificationStyle.xaml | 30 ++++++++++++------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml index 77b97ba6b58..cf0ba8c691b 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.xaml @@ -1,16 +1,16 @@ - + - - + - + diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml index daffd3dda8e..87b217d0d13 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml +++ b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml @@ -8,18 +8,26 @@ out below --> - - - - + + + + - - - - + + + + @@ -64,8 +72,10 @@ - - + + From 9b082377e2725a7fce2e8c760de2af930fb8bd3d Mon Sep 17 00:00:00 2001 From: Vincent Gromfeld Date: Thu, 2 Jul 2020 10:09:36 +0200 Subject: [PATCH 5/5] add missing timer stop --- .../InAppNotification/InAppNotification.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs index 03df7373b67..de838e989b0 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification/InAppNotification.cs @@ -80,16 +80,6 @@ protected override void OnApplyTemplate() /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) public void Show(int duration = 0) { - _dismissTimer.Stop(); - - var eventArgs = new InAppNotificationOpeningEventArgs(); - Opening?.Invoke(this, eventArgs); - - if (eventArgs.Cancel) - { - return; - } - // We keep our current content var notificationOptions = new NotificationOptions { @@ -258,6 +248,14 @@ private void UpdateContent(NotificationOptions notificationOptions) /// Information about the notification to display private void Show(NotificationOptions notificationOptions) { + var eventArgs = new InAppNotificationOpeningEventArgs(); + Opening?.Invoke(this, eventArgs); + + if (eventArgs.Cancel) + { + return; + } + var shouldDisplayImmediately = true; switch (StackMode) { @@ -288,6 +286,10 @@ private void Show(NotificationOptions notificationOptions) _dismissTimer.Interval = TimeSpan.FromMilliseconds(notificationOptions.Duration); _dismissTimer.Start(); } + else + { + _dismissTimer.Stop(); + } } } }