public void ShowNotification(INotification notification) { Argument.IsNotNull(() => notification); if (IsSuspended) { Log.Debug("Notifications are suspended, queueing notification"); _notificationsQueue.Enqueue(notification); return; } _dispatcherService.BeginInvoke(() => { EnsureMainWindow(); var hasActiveWindows = HasActiveWindows(); if (!hasActiveWindows && notification.Priority <= NotificationPriority.Normal) { Log.Debug($"Not showing notification '{notification}' since priority is '{notification.Priority}' and app has no active windows."); return; } Log.Debug("Showing notification '{0}'", notification); var notificationLocation = _notificationPositionService.GetLeftTopCorner(NotificationSize, CurrentNotifications.Count); var popup = new Popup(); popup.AllowsTransparency = true; popup.Placement = PlacementMode.Custom; popup.CustomPopupPlacementCallback += (popupSize, targetSize, offset) => { var x = DpiHelper.CalculateSize(DpiHelper.DpiX, notificationLocation.X); var y = DpiHelper.CalculateSize(DpiHelper.DpiY, notificationLocation.Y); var popupPlacement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.None); var ttplaces = new[] { popupPlacement }; return(ttplaces); }; var notificationViewModel = _viewModelFactory.CreateViewModel <NotificationViewModel>(notification, null); notificationViewModel.ClosedAsync += async(sender, e) => popup.IsOpen = false; var notificationView = new NotificationView(); notificationView.DataContext = notificationViewModel; notificationView.Unloaded += OnNotificationViewUnloaded; popup.Child = notificationView; popup.IsOpen = true; OpenedNotification?.Invoke(this, new NotificationEventArgs(notification)); CurrentNotifications.Add(notification); }); }
public void ShowNotification(INotification notification) { Argument.IsNotNull(() => notification); if (IsSuspended) { Log.Debug("Notifications are suspended, queueing notification"); _notificationsQueue.Enqueue(notification); return; } EnsureMainWindow(); _dispatcherService.BeginInvoke(() => { Log.Debug("Showing notification '{0}'", notification); var notificationLocation = _notificationPositionService.GetLeftTopCorner(NotificationSize, CurrentNotifications.Count); var popup = new Popup(); popup.AllowsTransparency = true; popup.Placement = PlacementMode.Custom; popup.CustomPopupPlacementCallback += (popupSize, targetSize, offset) => { var x = DpiHelper.CalculateSize(DpiHelper.DpiX, notificationLocation.X); var y = DpiHelper.CalculateSize(DpiHelper.DpiY, notificationLocation.Y); var popupPlacement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.None); var ttplaces = new [] { popupPlacement }; return(ttplaces); }; //popup.Placement = PlacementMode.AbsolutePoint; //popup.PlacementRectangle = new Rect(notificationLocation.X, notificationLocation.Y, NotificationSize.Width, NotificationSize.Height); var notificationViewModel = _viewModelFactory.CreateViewModel <NotificationViewModel>(notification); notificationViewModel.ClosedAsync += async(sender, e) => popup.IsOpen = false; // TODO: consider factory var notificationView = new NotificationView(); notificationView.DataContext = notificationViewModel; notificationView.Unloaded += OnNotificationViewUnloaded; popup.Child = notificationView; popup.IsOpen = true; OpenedNotification.SafeInvoke(this, new NotificationEventArgs(notification)); CurrentNotifications.Add(notification); }); }
public void ShowNotification(INotification notification) { Argument.IsNotNull(() => notification); if (IsSuspended) { Log.Debug("Notifications are suspended, queueing notification"); _notificationsQueue.Enqueue(notification); return; } EnsureMainWindow(); _dispatcherService.BeginInvoke(() => { Log.Debug("Showing notification '{0}'", notification); var notificationLocation = _notificationPositionService.GetLeftTopCorner(NotificationSize, CurrentNotifications.Count); var popup = new Popup(); popup.AllowsTransparency = true; popup.Placement = PlacementMode.Custom; popup.CustomPopupPlacementCallback += (popupSize, targetSize, offset) => { var x = DpiHelper.CalculateSize(DpiHelper.DpiX, notificationLocation.X); var y = DpiHelper.CalculateSize(DpiHelper.DpiY, notificationLocation.Y); var popupPlacement = new CustomPopupPlacement(new Point(x, y), PopupPrimaryAxis.None); var ttplaces = new [] { popupPlacement }; return ttplaces; }; //popup.Placement = PlacementMode.AbsolutePoint; //popup.PlacementRectangle = new Rect(notificationLocation.X, notificationLocation.Y, NotificationSize.Width, NotificationSize.Height); var notificationViewModel = _viewModelFactory.CreateViewModel<NotificationViewModel>(notification); notificationViewModel.ClosedAsync += async (sender, e) => popup.IsOpen = false; // TODO: consider factory var notificationView = new NotificationView(); notificationView.DataContext = notificationViewModel; notificationView.Unloaded += OnNotificationViewUnloaded; popup.Child = notificationView; popup.IsOpen = true; OpenedNotification.SafeInvoke(this, new NotificationEventArgs(notification)); CurrentNotifications.Add(notification); }); }