Back to Devexpress

TreeViewControl.ShowNodeMenu Event

wpf-devexpress-dot-xpf-dot-grid-dot-treeviewcontrol-68468d15.md

latest5.8 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event TreeViewShowNodeMenuEventHandler ShowNodeMenu
vb
Public Event ShowNodeMenu As TreeViewShowNodeMenuEventHandler

Event Data

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

PropertyDescription
CustomizationsGets a collection of actions for the context menu.
HandledGets 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.
ItemsGets a collection of context menu items.
NodeGets a node for which the context menu is shown.
OriginalSourceGets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.
RoutedEventGets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.
SourceGets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.
TargetElementGets a UI element for which the context menu is shown.

The event data class exposes the following methods:

MethodDescription
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:

xaml
<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>
csharp
void treeview_ShowNodeMenu(object sender, DevExpress.Xpf.Grid.TreeList.TreeViewNodeMenuEventArgs e) {
    if (e.Node.Level == 0) e.Customizations.Add(new RemoveAction { ElementName = "deleteNode"} );
}
vb
Private Sub treeview_ShowNodeMenu(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.TreeList.TreeViewNodeMenuEventArgs)
    If e.Node.Level = 0 Then e.Customizations.Add(New RemoveAction With {
        .ElementName = "deleteNode"
    })
End Sub

See Also

TreeViewControl Class

TreeViewControl Members

DevExpress.Xpf.Grid Namespace