public async Task Show(string title, string text, int?timeShow = 5000)
        {
            var w = new NotificationWindow();

            w.ShowInTaskbar = false;
            w.DataContext   = new NotificationWindowViewModel(title, text, w);
            w.Show();
            w.Closed += delegate { Reposition(); };
            Add(w);

            if (timeShow != null)
            {
                await Task.Run(async() =>
                {
                    for (int i = 0; i < timeShow / 100; i++)
                    {
                        await Task.Delay(100);
                        if (w.IsClosed)
                        {
                            break;
                        }
                    }
                });

                if (!w.IsClosed)
                {
                    w.Close();
                }
            }
        }
Exemple #2
0
 protected override void OnExit(ExitEventArgs e)
 {
     asyncTaskRunner.CancelTasks();
     if (notifierWindow != null)
     {
         notifierWindow.Close();
     }
     base.OnExit(e);
 }
        public async Task <ButtonsResult> ShowWithButtons(string title, string text, ButtonsType buttonsType,
                                                          int?timeShow = 5000)
        {
            var w = new NotificationWindow();

            switch (buttonsType)
            {
            case ButtonsType.Ok:
                w.DataContext = new NotificationWindowViewModel(title, text, w, NotificationType.Ok);
                break;

            case ButtonsType.YesNo:
                w.DataContext = new NotificationWindowViewModel(title, text, w, NotificationType.YesNo);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(buttonsType), buttonsType, null);
            }

            w.Closed += delegate { Reposition(); };
            w.Show();
            Add(w);
            if (timeShow != null)
            {
                await Task.Run(async() =>
                {
                    for (int i = 0; i < timeShow / 100; i++)
                    {
                        await Task.Delay(100);
                        if (w.IsClosed)
                        {
                            break;
                        }
                    }
                });

                if (!w.IsClosed)
                {
                    w.Close();
                }
            }
            else
            {
                while (true)
                {
                    await Task.Delay(100);

                    if (w.IsClosed)
                    {
                        break;
                    }
                }
            }
            return(w.ButtonsResult);
        }
        private void cmdNotify_Click(object sender, RoutedEventArgs e)
        {
            if (Application.Current.HasElevatedPermissions)
            {
                CustomNotification notification = new CustomNotification();
                notification.Message = "You have just been notified. The time is " + DateTime.Now.ToLongTimeString() + ".";
                window.Content       = notification;

                window.Close();
                window.Show(5000);
            }
            else
            {
                MessageBox.Show("This feature is not available while you are running in the browser with low trust.");
                // (Implement a different notification strategy here.)
            }
        }
        private void ShowWindow(ITweetItem tweet)
        {
            if (_window == null)
            {
                _window = new NotificationWindow
                {
                    Width   = 400,
                    Height  = 100,
                    Content = new NotificationControl()
                };
            }

            if (_appInfo.IsNotificationsEnabled)
            {
                _window.Content.DataContext = tweet;
                _window.Close();
                _window.Show(5000);
            }
        }
        public async Task <string> ShowWithInput(string title, string text,
                                                 int?timeShow = null)
        {
            var w = new NotificationWindow();

            w.DataContext = new NotificationWindowViewModel(title, text, w, NotificationType.Input);
            w.Closed     += delegate { Reposition(); };
            w.Show();
            Add(w);
            if (timeShow != null)
            {
                await Task.Run(async() =>
                {
                    for (int i = 0; i < timeShow / 100; i++)
                    {
                        await Task.Delay(100);
                        if (w.IsClosed)
                        {
                            break;
                        }
                    }
                });

                if (!w.IsClosed)
                {
                    w.Close();
                }
            }
            else
            {
                while (true)
                {
                    await Task.Delay(100);

                    if (w.IsClosed)
                    {
                        break;
                    }
                }
            }

            return(w.TextResult);
        }
        public NotificationWindowViewModel CreateNotificationWindow()
        {
            var window    = new NotificationWindow();
            var viewModel = createNotificationWindowViewModel();

            EventHandler <RequestShowEventArgs> requestShowHandler = (sender, args) => window.ShowOnMonitor(args.TargetMonitor);
            EventHandler requestCloseHandler = (sender, args) => window.Close();

            viewModel.RequestClose += requestCloseHandler;
            viewModel.RequestShow  += requestShowHandler;

            window.DataContext = viewModel;
            window.Closed     += (sender, args) =>
            {
                viewModel.RequestClose -= requestCloseHandler;
                viewModel.RequestShow  -= requestShowHandler;
            };

            return(viewModel);
        }
        private static IDisposable ShowDesktopWindow(int index)
        {
            var vmodel = new NotificationWindowViewModel
            {
                Title  = ProductInfo.Title,
                Header = "Virtual Desktop Switched",
                Body   = "Current Desktop: Desktop " + index,
            };
            var source = new CancellationTokenSource();
            var window = new NotificationWindow()
            {
                DataContext = vmodel,
            };

            window.Show();

            Task.Delay(TimeSpan.FromMilliseconds(Settings.General.NotificationDuration), source.Token)
            .ContinueWith(_ => window.Close(), TaskScheduler.FromCurrentSynchronizationContext());

            return(Disposable.Create(() => source.Cancel()));
        }
        private void Account_Notify(object sender, AccountEventArgs e)
        {
            Debug.Print(e.Message);

            Application.Current.Dispatcher.InvokeAsync(async() =>
            {
                Window mainWindow        = Application.Current.MainWindow;
                NotificationWindow alarm = new NotificationWindow()
                {
                    DataContext = new NotificationWindowViewModel()
                    {
                        Message = e.Message
                    }
                };
                alarm.Owner = mainWindow;
                alarm.Left  = mainWindow.Left + mainWindow.Width - alarm.Width - 8;
                alarm.Top   = mainWindow.Top + mainWindow.Height - alarm.Height - 8;
                alarm.Show();
                await Task.Delay(2000);
                alarm.Close();
            });
        }
        private void btNotify_Click(object sender, RoutedEventArgs e)
        {
            if (Application.Current.IsRunningOutOfBrowser)
            {
                NotificationWindow notify = new NotificationWindow();
                notify.Height = 100;
                notify.Width  = 200;

                StackPanel sp   = new StackPanel();
                TextBlock  text = new TextBlock();
                text.Text = "Hello";
                sp.Children.Add(text);
                Button btClose = new Button();
                btClose.Content = "chiudi";
                btClose.Click  += delegate(object s, RoutedEventArgs ev)
                {
                    notify.Close();
                };
                sp.Children.Add(btClose);

                notify.Content = sp;
                notify.Show(5000);
            }
        }
Exemple #11
0
 protected override void OnExit(ExitEventArgs e)
 {
     notifierWindow?.Close();
     base.OnExit(e);
 }