protected override void OnStateChanged(EventArgs e) { if (this.WindowState == WindowState.Minimized && App.Settings.Current.Windows.MinimizeToSysTray) { if (_notifyIcon == null) { _notifyIcon = new NotifyIcon(this, App.ApplicationIcon); _notifyIcon.DoubleClicked += (sender, args) => { this.Show(); this.WindowState = _oldWindowState; this.Activate(); _notifyIcon.Hide(); }; _notifyIcon.RightClicked += (sender, args) => { var menu = this.FindResource("NotifyMenu") as ContextMenu; if (menu != null) { menu.IsOpen = true; System.Windows.Input.CommandManager.InvalidateRequerySuggested(); } }; } this.Hide(); _notifyIcon.Show(); } base.OnStateChanged(e); }
public static void HideNotifyIcon() { _notifyIcon?.Hide(); }