Back to Devexpress

PopupMenuShowingEventArgs.Customizations Property

wpf-devexpress-dot-xpf-dot-spreadsheet-dot-menu-dot-popupmenushowingeventargs-49f08aca.md

latest5.4 KB
Original Source

PopupMenuShowingEventArgs.Customizations Property

Provides access to the collection of context menu customization actions.

Namespace : DevExpress.Xpf.Spreadsheet.Menu

Assembly : DevExpress.Xpf.Spreadsheet.v25.2.dll

NuGet Package : DevExpress.Wpf.Spreadsheet

Declaration

csharp
public BarManagerActionCollection Customizations { get; }
vb
Public ReadOnly Property Customizations As BarManagerActionCollection

Property Value

TypeDescription
BarManagerActionCollection

A collection of bar actions used to customize the context menu.

|

Remarks

The Customizations property allows you to customize the Spreadsheet control’s context menus. You can add or remove menu items. Use the PopupMenuShowingEventArgs.MenuType property to determine for which spreadsheet element (a cell, row or column heading, drawing object, etc.) the menu is invoked.

The example below customizes the Cell context menu as follows:

  • Creates new Merge Cells and Highlight Cells items
  • Removes the Insert Comment and Hyperlink items

xaml
<dxsps:SpreadsheetControl x:Name="spreadsheetControl" 
                          PopupMenuShowing="spreadsheetControl_PopupMenuShowing"/>
csharp
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;
}
vb
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

See Also

PopupMenuShowingEventArgs Class

PopupMenuShowingEventArgs Members

DevExpress.Xpf.Spreadsheet.Menu Namespace