/// <summary>
        /// Dismiss the notification
        /// </summary>
        /// <param name="dismissKind">Kind of action that triggered dismiss event</param>
        private void Dismiss(InAppNotificationDismissKind dismissKind)
        {
            if (Visibility == Visibility.Visible)
            {
                // Continue to display notification if on remaining stacked notification
                if (_stackedNotificationOptions.Any())
                {
                    _stackedNotificationOptions.RemoveAt(0);

                    if (_stackedNotificationOptions.Any())
                    {
                        DisplayNextStackedNotification(_stackedNotificationOptions[0]);
                        return;
                    }
                }

                _animationTimer.Stop();

                var closingEventArgs = new InAppNotificationClosingEventArgs(dismissKind);
                Closing?.Invoke(this, closingEventArgs);

                if (closingEventArgs.Cancel)
                {
                    return;
                }

                VisualStateManager.GoToState(this, StateContentCollapsed, true);

                _lastDismissKind = dismissKind;

                _animationTimer.Interval = AnimationDuration;
                _animationTimer.Tick    += DismissAnimationTimer_Tick;
                _animationTimer.Start();
            }
        }
        /// <summary>
        /// Dismiss the notification
        /// </summary>
        /// <param name="dismissKind">Kind of action that triggered dismiss event</param>
        /// <param name="dismissAll">Indicates if one or all notifications should be dismissed.</param>
        private void Dismiss(InAppNotificationDismissKind dismissKind, bool dismissAll = false)
        {
            if (_stackedNotificationOptions.Count == 0)
            {
                // There is nothing to dismiss.
                return;
            }

            _dismissTimer.Stop();

            // Dismiss all if requested
            if (dismissAll)
            {
                _stackedNotificationOptions.Clear();
            }
            else
            {
                _stackedNotificationOptions.RemoveAt(0);
            }

            // Continue to display notification if on remaining stacked notification
            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;
        }
        /// <summary>
        /// Dismiss the notification
        /// </summary>
        /// <param name="dismissKind">Kind of action that triggered dismiss event</param>
        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();
                        }
                    }
        }
        private void Dismiss(InAppNotificationDismissKind dismissKind)
        {
            if (Visibility == Visibility.Visible)
            {
                _animationTimer.Stop();

                var closingEventArgs = new InAppNotificationClosingEventArgs(dismissKind, NotificationId);
                Closing?.Invoke(this, closingEventArgs);
                if (closingEventArgs.Cancel)
                {
                    return;
                }

                VisualStateManager.GoToState(this, StateContentCollapsed, true);

                _lastDismissKind = dismissKind;

                _animationTimer.Interval = AnimationDuration;
                _animationTimer.Tick    += DismissAnimationTimer_Tick;
                _animationTimer.Start();
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InAppNotificationClosingEventArgs"/> class.
 /// </summary>
 /// <param name="dismissKind">Dismiss kind that triggered the closing event</param>
 public InAppNotificationClosingEventArgs(InAppNotificationDismissKind dismissKind)
 {
     DismissKind = dismissKind;
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InAppNotificationClosingEventArgs"/> class.
 /// </summary>
 /// <param name="dismissKind">Dismiss kind that triggered the closing event</param>
 public InAppNotificationClosingEventArgs(InAppNotificationDismissKind dismissKind, string id)
 {
     DismissKind = dismissKind;
     ID          = id;
 }