Skip to main content

DockLayoutManager.ShowingMenu Event

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

Namespace: DevExpress.Xpf.Docking

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

NuGet Package: DevExpress.Wpf.Docking

Declaration

public event ShowingMenuEventHandler ShowingMenu

Event Data

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

Property Description
ActionList Gets a collection of actions that manipulate bar objects. Inherited from ShowMenuEventArgs<T>.
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.
Items Gets a collection of BarItems that are displayed in the popup menu. Inherited from ShowMenuEventArgs<T>.
Menu Gets the context menu’s type. Inherited from ShowMenuEventArgs<T>.
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.
Show Gets or sets whether the popup menu is displayed. Inherited from ShowMenuEventArgs<T>.
Source Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
TargetElement Gets the UI element for which the context menu is shown. Inherited from ShowMenuEventArgs<T>.

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.

Example

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

View Example

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");
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ShowingMenu event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also