private void Current_StateChanged(object sender, LocalNotificationStateChangedEventArgs e) { switch (e.NewState) { // When a notification first gets hidden, it will expire (i.e. get removed from the visual tree). case LocalNotificationState.Hidden: { current.StateChanged -= Current_StateChanged; DisengageTimer(); grid.Children.Remove(current); current = null; if (q.Count > 0) { Show(q.Dequeue()); } } break; // When a notification gets shown when the timer is null (implying that it is shown for the first time), a new timer will be assigned to schedule hiding it. // The null check is so that when the notification switches to the 'Shown' state multiple times (e.g. after restoration), a new timer doesn't get assigned to it. case LocalNotificationState.Shown: { if (timer == null) { timer = new DispatcherTimer { Interval = current.TimeSpan ?? TimeSpan.Zero, }; if (current.TimeSpan != null) { timer.Tick += Timer_Tick; timer.Start(); } } } break; } }
/// <summary> /// Called when the notification switches to a <see cref="LocalNotificationState"/>. /// </summary> /// <param name="eventArgs">The <see cref="LocalNotificationStateChangedEventArgs"/> instance containing the event data.</param> protected virtual void OnStateChanged(LocalNotificationStateChangedEventArgs eventArgs) { }