WPF does not have its own notification bar icon component, and you need to refer to the Windows Class Library with the following specific code:
Public MainWindow () {InitializeComponent ();
icon ();
WSL = windowstate.minimized;
#region notification bar WindowState WSL;
System.Windows.Forms.NotifyIcon NotifyIcon = null;
private void icon () {This.notifyicon = new System.Windows.Forms.NotifyIcon (); This.notifyIcon.BalloonTipText = "ECMS service is running ..."; Sets the text to display when the program starts This.notifyIcon.Text = "ECMS service";//when minimized to the tray, the text displayed when the mouse clicks This.notifyIcon.Icon
= new System.Drawing.Icon ("./logo_48x48.ico");//program icon this.notifyIcon.Visible = true;
Right-click Menu--Opens menu item System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem ("open"); Open.
Click + + new EventHandler (ShowWindow);
Right-click Menu--Exit menu item System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem ("Exit"); Exit.
Click + + new EventHandler (CloseWindow);
Associated pallet control system.windows.forms.menuitem[] childen = new system.windows.forms.menuitem[] {open, exit};
Notifyicon.contextmenu = new System.Windows.Forms.ContextMenu (childen);
Notifyicon.mousedoubleclick + = Onnotifyicondoubleclick;
THIS.NOTIFYICON.SHOWBALLOONTIP (1000);
} private void Onnotifyicondoubleclick (object sender, EventArgs e) {/* * This section of code needs to explain: * When the window is normal double-click the icon to execute the code is such a process: * this. Show ()-->windowstate changed from Normail to minimized-->window_statechanged event execution (this. Hide ())-->windowstate from minimized to normal--> window Hide * Double-click the icon to execute this code is a process: * this.
Show ()-->windowstate changed from Normail to Minimized-->windowstate from minimized to normal--> window display * * This.
Show (); This. WindowState = Windowstate.minimized; This.
WindowState = Windowstate.normal;
Hidden taskbar icon when private void Window_statechanged (object sender, EventArgs e) {//Window minimized if (WindowState = = windowstate.minimized) {this.
Hide (); } private void ShowWindow (object sender, EventArgs e) {this.
Visibility = System.Windows.Visibility.Visible; This.
ShowInTaskbar = true; This.
Activate (); } private void Hidewindow (object sender, EventArgs e) {this.
ShowInTaskbar = false; This.
Visibility = System.Windows.Visibility.Hidden; } private void CloseWindow (object sender, EventArgs e) {System.Windows.Applicati On.
Current.shutdown (); } #endregion