/// <summary>Handles opening of views that are notification messages</summary> /// <param name="context">The request context.</param> /// <param name="overrideTimeout">Overrides the theme's default notification timeout.</param> /// <returns>True of view was handled</returns> protected virtual bool HandleNotificationMessage(RequestContext context, TimeSpan?overrideTimeout = null) { var notificationResult = context.Result as NotificationMessageResult; if (notificationResult == null) { return(false); } var wrapper = new NotificationViewResultWrapper { Model = notificationResult.Model }; if (notificationResult.View != null) { wrapper.View = notificationResult.View; notificationResult.View.DataContext = wrapper.Model; } else { wrapper.View = Controller.LoadView(StandardViews.Notification); if (wrapper.View != null) { wrapper.View.DataContext = wrapper.Model; } } if (NotificationSort == NotificationSort.NewestFirst) { CurrentNotifications.Add(wrapper); } else { CurrentNotifications.Insert(0, wrapper); } while (CurrentNotifications.Count > MaximumNotificationCount) { // Handling this like a stack, popping the oldest one off if (NotificationSort == NotificationSort.NewestFirst) { CurrentNotifications.RemoveAt(0); } else { CurrentNotifications.RemoveAt(CurrentNotifications.Count - 1); } } CurrentNotificationsCount = CurrentNotifications.Count; RaiseEvent(new RoutedEventArgs(NotificationChangedEvent)); var timeout = overrideTimeout ?? NotificationTimeout; wrapper.InternalTimer = new Timer(state => Application.Current.Dispatcher.BeginInvoke(new Action(() => { CurrentNotifications.Remove(wrapper); CurrentNotificationsCount = CurrentNotifications.Count; })), null, timeout, new TimeSpan(-1)); return(true); }
/// <summary>Handles opening of views that are notification messages</summary> /// <param name="context">The request context.</param> /// <param name="overrideTimeout">Overrides the theme's default notification timeout.</param> /// <returns>True of view was handled</returns> protected virtual bool HandleNotificationMessage(RequestContext context, TimeSpan? overrideTimeout = null) { var notificationResult = context.Result as NotificationMessageResult; if (notificationResult == null) return false; var wrapper = new NotificationViewResultWrapper {Model = notificationResult.Model}; if (notificationResult.View != null) { wrapper.View = notificationResult.View; notificationResult.View.DataContext = wrapper.Model; } else { wrapper.View = Controller.LoadView(StandardViews.Notification); if (wrapper.View != null) wrapper.View.DataContext = wrapper.Model; } if (NotificationSort == NotificationSort.NewestFirst) CurrentNotifications.Add(wrapper); else CurrentNotifications.Insert(0, wrapper); while (CurrentNotifications.Count > MaximumNotificationCount) { // Handling this like a stack, popping the oldest one off if (NotificationSort == NotificationSort.NewestFirst) CurrentNotifications.RemoveAt(0); else CurrentNotifications.RemoveAt(CurrentNotifications.Count - 1); } CurrentNotificationsCount = CurrentNotifications.Count; RaiseEvent(new RoutedEventArgs(NotificationChangedEvent)); var timeout = overrideTimeout ?? NotificationTimeout; wrapper.InternalTimer = new Timer(state => Application.Current.Dispatcher.BeginInvoke(new Action(() => { CurrentNotifications.Remove(wrapper); CurrentNotificationsCount = CurrentNotifications.Count; })), null, timeout, new TimeSpan(-1)); return true; }