public void CreateNotification(ICollection<Inline> title, ICollection<Inline> message, Color color, TimeSpan showTime) { var notification = new NotificationView(new NotificationViewModel() { Title = title, Message = message, BarBrush = App.GetBrush(color), }); notifications.Add(notification); notification.Show(); PlaceNotification(notification); var timer = new Timer(showTime.TotalMilliseconds); timer.Elapsed += (sender, e) => { timer.Stop(); timer.Dispose(); timers.Remove(timer); notification.Dispatcher.BeginInvoke(new Action(() => { notification.Close(); notifications.Remove(notification); })); }; timers.Add(timer); timer.Start(); }
void PlaceNotification(NotificationView notification) { if (App.Current.MainWindow != null) { var source = System.Windows.PresentationSource.FromVisual(notification); if (source != null) { var workArea = System.Windows.SystemParameters.WorkArea; var point = source.CompositionTarget.TransformToDevice.Transform(workArea.BottomRight); point.X -= notification.Width + 5; point.Y -= notifications.Count * notification.Height + 5; notification.Left = point.X; notification.Top = point.Y; } } }