in .NET Framework

Using ContextMenuStrip and NotifyIcon classes with WPF

There are many ways to get a notification icon displaying in the system tray, this is how I managed to get it working using Windows Presentation Framework:

public partial class ClassName : Window


private System.Windows.Forms.NotifyIcon m_notifyIcon;

private System.Windows.Forms.ContextMenuStrip m_contextMenu;

public ClassName()



//Initalize the context menu strip

m_contextMenu = new System.Windows.Forms.ContextMenuStrip();

System.Windows.Forms.ToolStripMenuItem mI1 = new System.Windows.Forms.ToolStripMenuItem();

mI1.Text = “Menu One”;

mI1.Click += new EventHandler(Click_Handler); //Add Click Handler


System.Windows.Forms.ToolStripMenuItem mI2 = new System.Windows.Forms.ToolStripMenuItem();

mI2.Text = “Menu Two”;

mI2.Click += new EventHandler(Click_Handler); //Add Click Handler


//Initalize Notify Icon

m_notifyIcon = new System.Windows.Forms.NotifyIcon();

m_notifyIcon.Text = “Application Title”;

m_notifyIcon.Icon = new System.Drawing.Icon(“Icon.ico”);

m_notifyIcon.ContextMenuStrip = m_contextMenu; //Associate the contextmenustrip with notify icon

m_notifyIcon.Visible = true;



  • Related Content by Tag