/// <summary> /// Display the notification window in specified direction of the screen /// </summary> /// <param name="window"> The window object</param> /// <param name="notificationFlowDirection"> Direction in which new notifications will appear.</param> private static void SetWindowDirection(Window window, NotificationFlowDirection notificationFlowDirection) { var workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea; var transform = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformFromDevice; var corner = transform.Transform(new Point(workingArea.Right, workingArea.Bottom)); switch (notificationFlowDirection) { case NotificationFlowDirection.RightBottom: window.Left = corner.X - window.Width - window.Margin.Right - Margin; window.Top = corner.Y - window.Height - window.Margin.Top; break; case NotificationFlowDirection.LeftBottom: window.Left = 0; window.Top = corner.Y - window.Height - window.Margin.Top; break; case NotificationFlowDirection.LeftUp: window.Left = 0; window.Top = 0; break; case NotificationFlowDirection.RightUp: window.Left = corner.X - window.Width - window.Margin.Right - Margin; window.Top = 0; break; default: window.Left = corner.X - window.Width - window.Margin.Right - Margin; window.Top = corner.Y - window.Height - window.Margin.Top; break; } }
/// <summary> /// Shows the specified window as a notification. /// </summary> /// <param name="window">The window.</param> /// <param name="displayDuration">The display duration.</param> public static void Show(Window window, TimeSpan displayDuration, NotificationFlowDirection notificationFlowDirection) { BehaviorCollection behaviors = Interaction.GetBehaviors(window); behaviors.Add(new FadeBehavior()); behaviors.Add(new SlideBehavior()); SetWindowDirection(window, notificationFlowDirection); notificationWindowsCount += 1; WindowInfo windowInfo = new WindowInfo() { ID = notificationWindowsCount, DisplayDuration = displayDuration, Window = window }; windowInfo.Window.Closed += Window_Closed; if (notificationWindows.Count + 1 > MAX_NOTIFICATIONS) { notificationsBuffer.Add(windowInfo); } else { StartWindowCloseTimer(windowInfo); window.Show(); notificationWindows.Add(windowInfo); } }
/// <summary> /// Initialises the configuration object. /// </summary> /// <param name="displayDuration">The notification display duration. set it TimeSpan.Zero to use default value </param> /// <param name="width">The notification width. set it to null to use default value</param> /// <param name="height">The notification height. set it to null to use default value</param> /// <param name="templateName">The notification template name. set it to null to use default value</param> /// <param name="notificationFlowDirection">The notification flow direction. set it to null to use default value (RightBottom)</param> public NotificationConfiguration(TimeSpan displayDuration, int? width, int? height, string templateName, NotificationFlowDirection? notificationFlowDirection) { DisplayDuration = displayDuration > TimeSpan.Zero ? displayDuration : DefaultDisplayDuration; Width = width.HasValue ? width : DefaultWidth; Height = height.HasValue ? height : DefaultHeight; TemplateName = !string.IsNullOrEmpty(templateName) ? templateName : DefaultTemplateName; NotificationFlowDirection = notificationFlowDirection ?? NotificationFlowDirection.RightBottom; }
/// <summary> /// Shows the specified window as a notification. /// </summary> /// <param name="window">The window.</param> /// <param name="displayDuration">The display duration.</param> public static void Show(Window window, TimeSpan displayDuration, NotificationFlowDirection notificationFlowDirection) { BehaviorCollection behaviors = Interaction.GetBehaviors(window); behaviors.Add(new FadeBehavior()); behaviors.Add(new SlideBehavior()); SetWindowDirection(window, notificationFlowDirection); notificationWindowsCount += 1; WindowInfo windowInfo = new WindowInfo() { ID = notificationWindowsCount, DisplayDuration = displayDuration, Window = window }; windowInfo.Window.Closed += Window_Closed; if (notificationWindows.Count + 1 > MAX_NOTIFICATIONS) { notificationsBuffer.Add(windowInfo); } else { Observable .Timer(displayDuration) .ObserveOnDispatcher() .Subscribe(x => OnTimerElapsed(windowInfo)); notificationWindows.Add(windowInfo); window.Show(); } }