public NotificationBalloon(INotificationBalloonViewModel viewModel) { DataContextChanged += OnDataContextChanged; DataContext = viewModel; _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(_viewModel.Timeout) }; _timer.Tick += (sender, args) => _viewModel.Close(); _viewModel.Shown += (sender, args) => _timer.Start(); Loaded += OnLoaded_ExecuteShowCommand; Loaded += OnLoaded_SlideLeftAnimation; _viewModel.Closing += OnClosingBalloon_SlideRightAnimation; InitializeComponent(); }
private void ShowNotification(INotificationBalloonViewModel notification) { if (notification == null) { return; } var notificationBalloon = new NotificationBalloon(notification); notificationBalloon.ClosingAnimationCompleted += (o, eventArgs) => { NotifyIcon.CloseBalloon(); if (!notification.ClosedCommand.CanExecute(null)) { return; } notification.ClosedCommand.Execute(null); }; // NotificationBalloon handles animation and timeout itself NotifyIcon.ShowCustomBalloon(notificationBalloon, PopupAnimation.None, null); // Place popup against right edge of screen NotifyIcon.CustomBalloon.HorizontalOffset += 1; }
public NotificationDispatcherNotification(INotificationBalloonViewModel notification) { Notification = notification; }
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e) { _viewModel = e.NewValue as INotificationBalloonViewModel ?? throw new InvalidOperationException("DataContext must be of type: INotificationBalloonViewModel"); }