예제 #1
0
 void OpenToastWindow()
 {
     window = new ToastWindow()
     {
         DataContext   = new ReadOnlyObservableCollection <ToastViewModel>(toasts),
         HoldCommand   = new RelayCommand <ToastViewModel>(HoldToast),
         UnholdCommand = new RelayCommand <ToastViewModel>(UnholdToast)
     };
     window.Show();
 }
예제 #2
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);
                    }
                };
            }
        }