wpf-devexpress-dot-xpf-dot-spreadsheet-dot-spreadsheetcontrol-6eeb8ed6.md
Allows you to customize the Spreadsheet control’s context menus.
Namespace : DevExpress.Xpf.Spreadsheet
Assembly : DevExpress.Xpf.Spreadsheet.v25.2.dll
NuGet Package : DevExpress.Wpf.Spreadsheet
public event EventHandler<PopupMenuShowingEventArgs> PopupMenuShowing
Public Event PopupMenuShowing As EventHandler(Of PopupMenuShowingEventArgs)
The PopupMenuShowing event's data class is PopupMenuShowingEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Customizations | Provides access to the collection of context menu customization actions. |
| Menu | Gets or sets the context menu for which the event is raised. |
| MenuType | Indicates a spreadsheet element for which the context menu is invoked. |
Handle the PopupMenuShowing event to modify context menu items.
Use the PopupMenuShowingEventArgs.Customizations property to add or remove items. The PopupMenuShowingEventArgs.MenuType property allows you to determine for which spreadsheet element (a cell, row or column heading, drawing object, etc.) the menu is invoked. To obtain the context menu for which the event is raised, use the PopupMenuShowingEventArgs.Menu property.
The example below customizes the Cell context menu as follows:
<dxsps:SpreadsheetControl x:Name="spreadsheetControl"
PopupMenuShowing="spreadsheetControl_PopupMenuShowing"/>
using DevExpress.Xpf.Bars;
using DevExpress.Xpf.Spreadsheet;
using DevExpress.Xpf.Spreadsheet.Menu;
using DevExpress.XtraSpreadsheet.Commands;
// ...
private void spreadsheetControl_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e) {
// Check whether the event is raised for a spreadsheet cell.
if (e.MenuType == SpreadsheetMenuType.Cell) {
// Create a menu item to merge selected cells
// and bind this item to the spreadsheet command.
e.Customizations.Add(new BarButtonItem() {
Command = SpreadsheetUICommand.EditingMergeAndCenterCells,
Content = "Merge Cells",
CommandParameter = spreadsheetControl
});
// Create a custom menu item to highlight selected cells.
var menuItem = new BarButtonItem();
menuItem.Name = "highlightCellsItem";
menuItem.Content = "Highlight Cells";
menuItem.ItemClick += MenuItem_ItemClick;
e.Customizations.Add(menuItem);
}
// Remove the "Insert Comment" item from the menu.
e.Customizations.Add(new RemoveSpreadsheetCommandAction() {
Id = SpreadsheetCommandId.ReviewInsertCommentContextMenuItem
});
// Remove the "Hyperlink" item from the menu.
e.Customizations.Add(new RemoveSpreadsheetCommandAction() {
Id = SpreadsheetCommandId.InsertHyperlinkContextMenuItem
});
}
private void MenuItem_ItemClick(object sender, ItemClickEventArgs e) {
// Fill selected cells with the yellow color.
spreadsheetControl.Selection.FillColor = System.Drawing.Color.Yellow;
}
Imports DevExpress.Xpf.Bars
Imports DevExpress.Xpf.Spreadsheet
Imports DevExpress.Xpf.Spreadsheet.Menu
Imports DevExpress.XtraSpreadsheet.Commands
' ...
Private Sub spreadsheetControl_PopupMenuShowing(ByVal sender As Object, ByVal e As PopupMenuShowingEventArgs)
' Check whether the event is raised for a spreadsheet cell.
If e.MenuType = SpreadsheetMenuType.Cell Then
' Create a menu item to merge selected cells
' and bind this item to the spreadsheet command.
e.Customizations.Add(New BarButtonItem() With {
.Command = SpreadsheetUICommand.EditingMergeAndCenterCells,
.Content = "Merge Cells",
.CommandParameter = spreadsheetControl
})
' Create a custom menu item to highlight selected cells.
Dim menuItem As New BarButtonItem()
menuItem.Name = "highlightCellsItem"
menuItem.Content = "Highlight Cells"
menuItem.ItemClick += MenuItem_ItemClick
e.Customizations.Add(menuItem)
End If
' Remove the "Insert Comment" item from the menu.
e.Customizations.Add(New RemoveSpreadsheetCommandAction() With {
.Id = SpreadsheetCommandId.ReviewInsertCommentContextMenuItem})
' Remove the "Hyperlink" item from the menu.
e.Customizations.Add(New RemoveSpreadsheetCommandAction() With {
.Id = SpreadsheetCommandId.InsertHyperlinkContextMenuItem})
End Sub
Private Sub MenuItem_ItemClick(ByVal sender As Object, ByVal e As ItemClickEventArgs)
' Fill selected cells with the yellow color.
spreadsheetControl.Selection.FillColor = System.Drawing.Color.Yellow
End Sub
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the PopupMenuShowing event.
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.
wpf-spreadsheet-customize-context-menu/CS/MenuCustomization/MainWindow.xaml#L33
BarManager="{Binding ElementName=barManager1, Mode=OneTime}"
PopupMenuShowing="SpreadsheetControlPopupMenuShowing">
<dxsps:SpreadsheetControl.MenuCustomizations>
#line 33 "..\..\..\MainWindow.xaml"
this.spreadsheetControl1.PopupMenuShowing += new System.EventHandler<DevExpress.Xpf.Spreadsheet.Menu.PopupMenuShowingEventArgs>(this.SpreadsheetControlPopupMenuShowing);
wpf-spreadsheet-customize-context-menu/VB/MenuCustomization/obj.NetFX/Debug/MainWindow.g.vb#L143
#ExternalSource("..\..\MainWindow.xaml",33)
AddHandler Me.spreadsheetControl1.PopupMenuShowing, New System.EventHandler(Of DevExpress.Xpf.Spreadsheet.Menu.PopupMenuShowingEventArgs)(AddressOf Me.SpreadsheetControlPopupMenuShowing)
See Also