private void InitToastWindow() { if (this.ToastWindow != null) return; this.ToastWindow = new ToastWindow(); Application.Current.MainWindow.Closing += (sender, e) => this.ToastWindow.Close(); }
void OpenToastWindow() { window = new ToastWindow() { DataContext = new ReadOnlyObservableCollection <ToastViewModel>(toasts), HoldCommand = new RelayCommand <ToastViewModel>(HoldToast), UnholdCommand = new RelayCommand <ToastViewModel>(UnholdToast) }; window.Show(); }
private void InitToastWindow() { if (this.ToastWindow != null) { return; } this.ToastWindow = new ToastWindow(); Application.Current.MainWindow.Closing += (sender, e) => this.ToastWindow.Close(); }
public void Toast(string text, int timeout = 5000) { Dispatcher.Invoke(() => { if (_toast == null) { _toast = new ToastWindow(); _toast.Owner = Window.GetWindow(this); } _toast.Add(text, timeout); }); }
private static void ShowToast(ToastWindowViewModel toastWindowViewModel) //TODO: can there be more than one toast at a time? if not a handling for this case is needed, maybe add to an itemsource { ToastWindow toastWindow = new ToastWindow { DataContext = toastWindowViewModel, Visibility = Visibility.Hidden }; toastWindow.Show(); Win32Api.W32Rect monitor = WindowHelper.GetPrimaryMonitor(); toastWindow.Left = monitor.Right - toastWindow.Width; toastWindow.Top = monitor.Bottom - toastWindow.Height; toastWindow.Visibility = Visibility.Visible; if (toastWindowViewModel.Behaviour == ToastBehaviour.TimedShort) { toastWindow.Timer = new Timer(HideToast, toastWindow, SHORT_TIMED_TOAST, 100); toastWindow.MouseOverChanged += delegate(object sender, bool isMouseOver) { if (isMouseOver) { toastWindow.Timer.Change(Timeout.Infinite, Timeout.Infinite); toastWindow.Opacity = 1; } else { toastWindow.Timer.Change(SHORT_TIMED_TOAST, 100); } }; } else if (toastWindowViewModel.Behaviour == ToastBehaviour.TimedLong) { toastWindow.Timer = new Timer(HideToast, toastWindow, LONG_TIMED_TOAST, 100); toastWindow.MouseOverChanged += delegate(object sender, bool isMouseOver) { if (isMouseOver) { toastWindow.Timer.Change(Timeout.Infinite, Timeout.Infinite); toastWindow.Opacity = 1; } else { toastWindow.Timer.Change(LONG_TIMED_TOAST, 100); } }; } }
void CloseToastWindow() { window.Close(); window = null; }