Skip to main content

GridMenuEventArgs.TargetElement Property

Gets the UI element for which the context menu is shown.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v22.1.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core


public IInputElement TargetElement { get; }

Property Value

Type Description

The element displayed within a View for which the context menu is shown.


  • Column Menu

    The TargetElement property returns the GridColumnHeader object that represents the column header for which the context menu is shown.

  • Cell Menu

    The TargetElement property returns the DevExpress.Xpf.Grid.GridCellContentPresenter object that represents the data cell for which the context menu is shown.

  • GroupPanel Menu

    The TargetElement property returns the ContentControl object that represents the Group Panel.

  • Summary Menu

    The TargetElement property returns the DevExpress.Xpf.Grid.GridTotalSummary object.


The following example demonstrates how to modify a column header in a grid’s Table View. This sample adds a button with an icon to a column header’s customization area.

Define a DataTemplate and assign it to the DataViewBase.ColumnHeaderCustomizationAreaTemplate property. This template specifies a button and its properties. For example, the context menu is invoked when you click the button, and the context menu is disabled when you right-click the column header or the custom button within it.

View Example

    <dxg:TableView Name="view" ShowGridMenu="TableView_ShowGridMenu">
                <Button Tag="custom" Click="Button_Click" PreviewMouseRightButtonUp="Button_PreviewMouseRightButtonUp" 
                        dxg:GridPopupMenu.GridMenuType="{x:Static dxg:GridMenuType.Column}">
                        <ControlTemplate TargetType="{x:Type Button}">
                            <Grid SnapsToDevicePixels="True" Background="Transparent">
                                <Path Name="path" Stretch="Fill" Fill="#FF0000FF" 
                                      Data="F1 M 1410.67,764.811L 1408.32,767.495C 1407.59,768.323 1406.36, 768.364 1405.59,767.586L 1405.41,767.414C 1404.64,766.636 1404.68, 765.407 1405.51,764.683L 1408.19,762.334C 1407.67,762.122 1407.1, 762 1406.5,762C 1404.01,762 1402,764.015 1402,766.5C 1402, 767.145 1402.14,767.755 1402.38,768.309L 1397.64,772.525C 1396.82, 773.257 1396.78,774.491 1397.56,775.269L 1397.73,775.44C 1398.51, 776.218 1399.74,776.182 1400.47,775.359L 1404.69,770.616C 1405.25, 770.86 1405.86,771.001 1406.5,771.001C 1408.98,771.001 1411, 768.985 1411,766.5C 1411,765.902 1410.88,765.333 1410.67,764.811 Z " 
                                      Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Fill" TargetName="path" Value="#FF00FF00" />
                                <Trigger Property="IsPressed" Value="True">
                                    <Setter Property="Fill" TargetName="path" Value="#FFFF0000" />
private void TableView_ShowGridMenu(object sender, GridMenuEventArgs e) {
    // Check whether this event was raised for a column's context menu.
    // If not - exit and leave the menu shown.
    if (e.MenuType != GridMenuType.Column) return;

    // Check whether this event was raised for a custom button.
    // If not - exit and hide the menu.
    if ((e.TargetElement as Control).Tag == null) {
        e.Handled = true;

private void Button_Click(object sender, RoutedEventArgs e) {
    // Show the context menu when a custom button is clicked.
    view.GridMenu.ShowPopup(sender as Button);

private void Button_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e) {
    // Don't show the context menu when a custom button is right-clicked.
    e.Handled = true;
See Also