GridMenuEventArgs.TargetElement Property
Gets the UI element for which the context menu is shown.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v18.2.Core.dll
Declaration
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.
Example
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).
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-add-a-custom-button-to-a-column-header-e1838.
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;
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the TargetElement property.
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.