Use of WPF ContextMenu, wpfcontextmenu
<Grid. contextMenu> <MenuItem Header = "add" Click = "MenuItem_Click"> </MenuItem> <MenuItem Header = "delete"> </MenuItem> <MenuItem Header = "Modify "> </MenuItem> </ContextMenu> </Grid. contextMenu> Add an image to the ContextMenu <MenuItem Header = "add" Click = "MenuItem_Click"> <MenuItem. icon> <Image Source = "image/titleIcon. ico "> </Image> </MenuItem. icon> </MenuItem> Add a split entry to the ContextMenu <Separator> </Separator>
Multiple calls to ContextMenu in WPF
In <Window. Resources>
</Window. Resources>
Medium,
You can use StaticResouce to call it later.
How to close the ContextMenu In the shortcut menu of the WPF tray icon
NotifyIcon has a ContextMenuStrip attribute. You can set this attribute directly. Do not set this attribute in the click event. This is intercepted in a previously written project. Stick it to it for you to see:
System. Windows. Forms. ContextMenuStrip contextMenu = new System. Windows. Forms. ContextMenuStrip ();
System. Windows. Forms. ToolStripMenuItem item1 = new System. Windows. Forms. ToolStripMenuItem ();
Item1.Click + = new EventHandler (item1_Click );
Item1.Text = "display main panel ";
System. Windows. Forms. ToolStripMenuItem item2 = new System. Windows. Forms. ToolStripMenuItem ();
Item2.Text = "quit ";
Item2.Click + = new EventHandler (item2_Click );
ContextMenu. Items. Add (item1 );
ContextMenu. Items. Add (item2 );
This. policyicon. ContextMenuStrip = contextMenu;