TreeViewControl.ShowNodeMenu Event
Occurs before a user opens a node’s context menu and allows you to customize this menu.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v24.1.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
Event Data
The ShowNodeMenu event's data class is TreeViewNodeMenuEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Customizations | Gets a collection of actions for the context menu. |
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 context menu items. |
Node | Gets a node for which the context menu is shown. |
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. |
TargetElement | Gets a UI element for which the context menu is shown. |
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
Use the NodeMenuCustomizations property to add items to a node’s context menu.
The following code sample removes the Delete Node item from the context menu for root nodes:
<Window
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
... >
<dxg:TreeViewControl ...
ShowNodeMenu="treeview_ShowNodeMenu">
<dxg:TreeViewControl.NodeMenuCustomizations>
<dxb:BarButtonItem Name="deleteNode" Content="Delete Node"/>
<dxb:BarButtonItem Name="copyNodeData" Content="Copy Node Data"/>
</dxg:TreeViewControl.NodeMenuCustomizations>
</dxg:TreeViewControl>
void treeview_ShowNodeMenu(object sender, DevExpress.Xpf.Grid.TreeList.TreeViewNodeMenuEventArgs e) {
if (e.Node.Level == 0) e.Customizations.Add(new RemoveAction { ElementName = "deleteNode"} );
}
See Also