A newer version of this page is available. Switch to the current version.

DockLayoutManager.ShowingMenu Event

Fires before showing a context menu, and allows it to be customized.

Namespace: DevExpress.Xpf.Docking

Assembly: DevExpress.Xpf.Docking.v19.1.dll

Declaration

public event ShowingMenuEventHandler ShowingMenu
Public Event ShowingMenu As ShowingMenuEventHandler

Event Data

The ShowingMenu event's data class is ShowingMenuEventArgs. The following properties provide information specific to this event:

Property Description
Handled Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.
OriginalSource Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEvent Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.

The event data class exposes the following methods:

Method Description
InvokeEventHandler(Delegate, Object) When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.
OnSetSource(Object) When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.

Remarks

This event allows you to respond to a context menu being invoked. You can handle it to change a menu, or prevent it from being displayed. To prevent the menu from being displayed, set the event's Show parameter to false.

To change the menu, add bar customization actions to the event's ActionList parameter. Bar customization actions are objects that implement the IBarManagerControllerAction interface. See DockLayoutManager.ContextMenuCustomizations for a list of most commonly used customization actions. To get information on all the available actions, see Bar Actions.

To customize context menus in XAML, use the DockLayoutManager.ContextMenuCustomizations and DockLayoutManager.ItemSelectorMenuCustomizations properties.

Examples

This example shows how to customize a context menu for a LayoutPanel via the DockManager.ShowingMenu event. The menu is customized using bar customization actions. In the example, two actions are created:

- a BarButtonItem object represents an action that adds the BarButtonItem object to the menu

- an InsertBarItemLinkAction object represents an action that inserts a bar item link to the menu (in the example, the inserted link represents a separator).Actions are added to the event's ActionList parameter and are executed after the ShowingMenu event handler is completed.

The following image shows the menu containing the custom items:

DockLayoutManager_ShowingMenu_ex

private void dockManager1_ShowingMenu(object sender, DevExpress.Xpf.Docking.Base.ShowingMenuEventArgs e) {
    ItemContextMenu menu = (e.Menu as ItemContextMenu);
    if (menu == null) return;
    // Action 1 - Insert a new About button at the first position in the menu.
    BarButtonItem actionAddAboutItem = new BarButtonItem();
    // Specify the position for the button via the InsertBarItemLinkAction.ItemLinkIndex attached property.
    InsertBarItemLinkAction.SetItemLinkIndex(actionAddAboutItem, 0);
    actionAddAboutItem.Content = "About...";
    actionAddAboutItem.ItemClick += new ItemClickEventHandler(btnAbout_ItemClick);
    // Action 2 - Insert a separator
    InsertBarItemLinkAction actionAddSeparator = new InsertBarItemLinkAction();
    actionAddSeparator.ItemLink = new BarItemLinkSeparator();
    actionAddSeparator.ItemLinkIndex = 1;

    // Add the actions to the ActionList
    e.ActionList.Add(actionAddAboutItem);
    e.ActionList.Add(actionAddSeparator);
}

void btnAbout_ItemClick(object sender, ItemClickEventArgs e) {
    MessageBox.Show("About window");
}
See Also