/// <summary> /// Show notification using the current template /// </summary> /// <param name="duration">Displayed duration of the notification in ms (less or equal 0 means infinite duration)</param> 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(); } } }
/// <summary> /// Handle the display of the notification based on the current StackMode /// </summary> /// <param name="notificationOptions">Information about the notification to display</param> private void Show(NotificationOptions notificationOptions) { var eventArgs = new InAppNotificationOpeningEventArgs(); Opening?.Invoke(this, eventArgs); if (eventArgs.Cancel) { return; } var shouldDisplayImmediately = true; switch (StackMode) { 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) { Visibility = Visibility.Visible; VisualStateManager.GoToState(this, StateContentVisible, true); UpdateContent(notificationOptions); if (notificationOptions.Duration > 0) { _dismissTimer.Interval = TimeSpan.FromMilliseconds(notificationOptions.Duration); _dismissTimer.Start(); } else { _dismissTimer.Stop(); } } }