GridPopupMenu Class
A pop-up menu displayed within a View.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v18.2.dll
Declaration
The following members return GridPopupMenu objects:
The GridPopupMenu object represents a context menu displayed within a View.
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).
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;
}
<dxg:GridControl.View>
<dxg:TableView Name="view" ShowGridMenu="TableView_ShowGridMenu">
<dxg:TableView.ColumnHeaderCustomizationAreaTemplate>
<DataTemplate>
<Button Tag="custom" Click="Button_Click" PreviewMouseRightButtonUp="Button_PreviewMouseRightButtonUp"
dxg:GridPopupMenu.GridMenuType="{x:Static dxg:GridMenuType.Column}">
<Button.Template>
<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" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Fill" TargetName="path" Value="#FF00FF00" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Fill" TargetName="path" Value="#FFFF0000" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</dxg:TableView.ColumnHeaderCustomizationAreaTemplate>
</dxg:TableView>
</dxg:GridControl.View>
Private Sub TableView_ShowGridMenu(ByVal sender As Object, ByVal e As GridMenuEventArgs)
' 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 Then
Return
End If
' Check whether this event was raised for a custom button.
' If not - exit and hide the menu.
If (TryCast(e.TargetElement, Control)).Tag Is Nothing Then
e.Handled = True
Return
End If
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Show the context menu when a custom button is clicked.
view.GridMenu.ShowPopup(TryCast(sender, Button))
End Sub
Private Sub Button_PreviewMouseRightButtonUp(ByVal sender As Object, ByVal e As _
MouseButtonEventArgs)
' Don't show the context menu when a custom button is right-clicked.
e.Handled = True
End Sub
See Also