MenuAction Class
A context menu item which represents an action to take in the designer.
Assembly: Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)
Use the MenuAction class to define a context menu item in the WPF Designer.
To show context menu items, inherit from the ContextMenuProvider class and create MenuAction items and an associated MenuGroup. These menu objects are usually created in the constructor of a class derived from PrimarySelectionContextMenuProvider, which shows the context menu on the primary selection.
Implement the logic for your MenuAction in the Execute event handler.
The MenuAction class is compatible with the WPF command system. Use the Command property to invoke the MenuAction programmatically, instead of through the user interface.
The following code example shows how to set up two MenuAction items, which set the Background property of a control at design time. For more information, see Walkthrough: Creating a MenuAction.
private MenuAction setBackgroundToBlueMenuAction; private MenuAction clearBackgroundMenuAction; ... // The provider's constructor sets up the MenuAction objects // and the the MenuGroup which holds them. public CustomContextMenuProvider() { // Set up the MenuAction which sets the control's // background to Blue. setBackgroundToBlueMenuAction = new MenuAction("Blue"); setBackgroundToBlueMenuAction.Checkable = true; setBackgroundToBlueMenuAction.Execute += new EventHandler<MenuActionEventArgs>(SetBackgroundToBlue_Execute); // Set up the MenuAction which sets the control's // background to its default value. clearBackgroundMenuAction = new MenuAction("Cleared"); clearBackgroundMenuAction.Checkable = true; clearBackgroundMenuAction.Execute += new EventHandler<MenuActionEventArgs>(ClearBackground_Execute); // Set up the MenuGroup which holds the MenuAction items. MenuGroup backgroundFlyoutGroup = new MenuGroup("SetBackgroundsGroup", "Set Background"); // If HasDropDown is false, the group appears inline, // instead of as a flyout. Set to true. backgroundFlyoutGroup.HasDropDown = true; backgroundFlyoutGroup.Items.Add(setBackgroundToBlueMenuAction); backgroundFlyoutGroup.Items.Add(clearBackgroundMenuAction); this.Items.Add(backgroundFlyoutGroup); // The UpdateItemStatus event is raised immediately before // this provider shows its tabs, which provides the opportunity // to set states. UpdateItemStatus += new EventHandler<MenuActionEventArgs>( CustomContextMenuProvider_UpdateItemStatus); }
Microsoft.Windows.Design.Interaction.MenuBase
Microsoft.Windows.Design.Interaction.MenuAction