Example #1
0
        private void InitToastWindow()
        {
            if (this.ToastWindow != null) return;

            this.ToastWindow = new ToastWindow();
            Application.Current.MainWindow.Closing += (sender, e) => this.ToastWindow.Close();
        }
Example #2
0
 void OpenToastWindow()
 {
     window = new ToastWindow()
     {
         DataContext   = new ReadOnlyObservableCollection <ToastViewModel>(toasts),
         HoldCommand   = new RelayCommand <ToastViewModel>(HoldToast),
         UnholdCommand = new RelayCommand <ToastViewModel>(UnholdToast)
     };
     window.Show();
 }
Example #3
0
        private void InitToastWindow()
        {
            if (this.ToastWindow != null)
            {
                return;
            }

            this.ToastWindow = new ToastWindow();
            Application.Current.MainWindow.Closing += (sender, e) => this.ToastWindow.Close();
        }
Example #4
0
 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);
     });
 }
Example #5
0
        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);
                    }
                };
            }
        }
Example #6
0
 void CloseToastWindow()
 {
     window.Close();
     window = null;
 }