private void SetColor(Color color) { App app = App.Current as App; NotifyIconComponent notifyIcon = app?.NotifyIcon; string toolTip = Resources.Colors.NoColorToolTip; string iconName = "no-color.ico"; switch (color) { case Color.Red: toolTip = Resources.Colors.RedToolTip; iconName = "red.ico"; break; case Color.Green: toolTip = Resources.Colors.GreenToolTip; iconName = "green.ico"; break; case Color.Blue: toolTip = Resources.Colors.BlueToolTip; iconName = "blue.ico"; break; } if (notifyIcon != null) { notifyIcon.ToolTip = toolTip; BitmapImage icon = new BitmapImage(new Uri($"pack://application:,,,/Resources/Icons/{iconName}", UriKind.Absolute));; notifyIcon.Icon = icon; } }
protected override void OnExit(ExitEventArgs e) { _notifyIconComponent?.Dispose(); _notifyIconComponent = null; base.OnExit(e); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // Find the notify icon component _notifyIconComponent = FindResource("NotifyIconComponent") as NotifyIconComponent; }
public void SimpleCreateDestory() { NotifyIconComponent notifyIconComponent = new NotifyIconComponent { Icon = new BitmapImage(new Uri(TEST_ICON, UriKind.Relative)), ToolTip = "This is a test", MenuActivation = EventType.SingleClick }; }
protected override void OnStartup(StartupEventArgs e) { // 检查是否为管理员权限运行 CheckAdministrator(); // 构造主窗口并显示 MainWindow = new MainView(); MainWindow.Show(); // 配置NotifyIcon _notifyIcon = new NotifyIconComponent(); MainWindow.StateChanged += (s, args) => { var win = s as MainView; if (win.WindowState == WindowState.Minimized) { win.ShowInTaskbar = false; _notifyIcon.ShowBalloonTip("NodeTapGui has been minimized!"); // 停止Ping Common.CommonEx.TimerGetHostDelays.Stop(); } }; _notifyIcon.OnShowWindowHandler += (s, args) => { // 还原显示窗口 if (MainWindow.WindowState == WindowState.Minimized) { MainWindow.WindowState = WindowState.Normal; MainWindow.ShowInTaskbar = true; // 开启Ping Common.CommonEx.TimerGetHostDelays.Start(); } }; }
private void SetupNotifyIcon() { // TODO: Need to Refactor the Core App Code so the Main Window Reference is // not passed around - Add AppController and bind to events from that. mainWindow = Main.GetInstance(); notify = new NotifyIconComponent(mainWindow) { IconTitle = Current.Application.AppTitle }; notify.TrayIconDoubleClicked += notify_TrayIconDoubleClicked; notify.TrayIconMouseMoved += notify_TrayIconMouseMoved; SetupTransitionMenu(); }