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

GridMenuEventArgs.TargetElement Property

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

Namespace: DevExpress.Xpf.Grid

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

Declaration

public IInputElement TargetElement { get; }
Public ReadOnly Property TargetElement As IInputElement

Property Value

Type Description
IInputElement

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

Remarks

  • 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.

Examples

The following example demonstrates how to modify a column header in a grid's Table View. In this sample, we illustrate how to add a button with an icon to a column header's customization area.

For this, it is necessary to define a DataTemplate, which represents a button, and assign it to the DataViewBase.ColumnHeaderCustomizationAreaTemplate property. This template specifies a button and some of its properties. For example, it invokes the standard context menu on clicking this button (but disables invoking this menu when either the column header or the custom button within it are clicked).

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;
        return;
    }
}

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