コード例 #1
0
        private void SetWindowVisible(Boolean isVisible)
        {
            if (isVisible)
            {
                Dispatcher.Invoke(() =>
                {
                    Visibility = Visibility.Visible;
                    Activate();

                    passwordWindow?.Close();
                    passwordWindow = null;
                });
            }
            else
            {
                Dispatcher.Invoke(() =>
                {
                    if (Visibility == Visibility.Visible)
                    {
                        Visibility = Visibility.Hidden;
                    }
                });
            }
        }
コード例 #2
0
        private void StartTrayIconThread()
        {
            trayContextMenu = new ContextMenu();

            trayOpenMenuItem  = new MenuItem("Open");
            trayCloseMenuItem = new MenuItem("Close");
            trayExitMenuItem  = new MenuItem("Exit");

            trayContextMenu.MenuItems.Add(0, trayOpenMenuItem);
            trayContextMenu.MenuItems.Add(1, trayCloseMenuItem);
            trayContextMenu.MenuItems.Add("-");
            trayContextMenu.MenuItems.Add(2, trayExitMenuItem);

            notifyIcon = new NotifyIcon
            {
                Visible     = true,
                Icon        = Properties.Resources.ChatWindowsIcon,
                Text        = ConfigurationManager.AppSettings["default_notification_title"],
                ContextMenu = trayContextMenu
            };

            notifyIcon.BalloonTipClicked += (sender, args) =>
            {
                Dispatcher.Invoke
                (
                    () =>
                {
                    if (IsVisible)
                    {
                        Activate();
                        InputTextBox.Focus();
                    }
                    else
                    {
                        passwordWindow = passwordWindow ?? new PasswordConfirmWindow(ConfigurationManager.AppSettings["default_password"],
                                                                                     () =>
                        {
                            Activate();
                            InputTextBox.Focus();
                            SetWindowVisible(true);
                        });
                        passwordWindow.Show();
                    }
                }
                );
            };

            trayOpenMenuItem.Click += (sender, args) =>
            {
                Dispatcher.Invoke
                (
                    () =>
                {
                    if (IsVisible)
                    {
                        Activate();
                        InputTextBox.Focus();
                    }
                    else
                    {
                        passwordWindow = passwordWindow ?? new PasswordConfirmWindow(ConfigurationManager.AppSettings["default_password"],
                                                                                     () =>
                        {
                            Activate();
                            InputTextBox.Focus();
                            SetWindowVisible(true);
                        });
                        passwordWindow.Show();
                    }
                }
                );
            };

            trayCloseMenuItem.Click += (sender, args) =>
            {
                SetWindowVisible(false);
            };

            trayExitMenuItem.Click += (sender, args) =>
            {
                notifyIcon.Dispose();
                Environment.Exit(0);
            };

            Application.Run();
        }