/// <summary> /// Adds a notification in the list. /// </summary> /// <param name="pNotification">The notification to add.</param> public void AddNotification(ANotificationViewModel pNotification) { if (pNotification == null) { return; } pNotification.Parent = this; this.Notifications.Add(pNotification); if (this.DisplayedNotification == null) { this.DisplayedNotification = pNotification; } if (pNotification.ShowOnRaised) { this.DisplayedNotification = pNotification; this.mParentButton.Dispatcher.Invoke((Action) delegate { this.mParentButton.IsOpen = true; }); } pNotification.TryToStartTimeout(); this.NotifyPropertyChanged("CanGoNext"); this.NotifyPropertyChanged("CanGoPrevious"); }
/// <summary> /// Closes a notification. /// </summary> /// <param name="pNotification">The notification to close.</param> /// <param name="pAnswer">The notification answer.</param> /// <param name="pTimeout">Flag indicating if the notification has been closed because of a timeout.</param> internal void CloseNotification(ANotificationViewModel pNotification, Answers pAnswer, bool pTimeout) { if (pNotification != null) { int lCurrentIndex = this.Notifications.IndexOf(pNotification); if (this.Notifications.Remove(pNotification)) { pNotification.Parent = null; pNotification.TryToStopLifeTimer(); if (this.Notifications.Any() == false) { this.DisplayedNotification = null; } else if (lCurrentIndex < this.Notifications.Count) { // Next notification is the one added after the closed one. this.DisplayedNotification = this.Notifications[lCurrentIndex]; } else if (lCurrentIndex > this.Notifications.Count - 1) { // Or the last if any notification is after the closed one. this.DisplayedNotification = this.Notifications[this.Notifications.Count - 1]; } // Cleaning the notification. pNotification.Clean(); this.NotifyNotificationClosed(pNotification.Id, pAnswer, pTimeout); } } }
/// <summary> /// Delegate called when the data context property changed. /// </summary> /// <param name="pObject">The modified object.</param> /// <param name="pEventArgs">The event arguments.</param> private static void OnDataContextChanged(DependencyObject pObject, DependencyPropertyChangedEventArgs pEventArgs) { NotificationView lControl = pObject as NotificationView; if (lControl != null) { BindingOperations.ClearAllBindings(lControl); ANotificationViewModel lNotificationViewModel = pEventArgs.NewValue as ANotificationViewModel; if (lNotificationViewModel != null) { Binding lHeaderBinding = new Binding(); lHeaderBinding.Source = lControl.ViewModel; lControl.SetBinding(HeaderProperty, lHeaderBinding); Binding lQuickStyleBinding = new Binding("QuickStyle"); lQuickStyleBinding.Source = lControl.ViewModel; lControl.SetBinding(QuickStyleProperty, lQuickStyleBinding); QuestionViewModel lQuestionViewModel = lNotificationViewModel as QuestionViewModel; if (lQuestionViewModel != null) { Binding lYesButtonStyleBinding = new Binding("YesButtonStyle"); lYesButtonStyleBinding.Source = lControl.ViewModel; lControl.SetBinding(YesButtonStyleProperty, lYesButtonStyleBinding); Binding lNoButtonStyleBinding = new Binding("NoButtonStyle"); lNoButtonStyleBinding.Source = lControl.ViewModel; lControl.SetBinding(NoButtonStyleProperty, lNoButtonStyleBinding); Binding lCancelButtonStyleBinding = new Binding("CancelButtonStyle"); lCancelButtonStyleBinding.Source = lControl.ViewModel; lControl.SetBinding(CancelButtonStyleProperty, lCancelButtonStyleBinding); } InformationViewModel lInformationViewModel = lNotificationViewModel as InformationViewModel; if (lInformationViewModel != null) { Binding lOkButtonStyleBinding = new Binding("OkButtonStyle"); lOkButtonStyleBinding.Source = lControl.ViewModel; lControl.SetBinding(OkButtonStyleProperty, lOkButtonStyleBinding); } } lControl.UpdateState(); } }