Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

SpreadsheetMenuCustomization.Customizations Property

Allows you to customize the Spreadsheet control’s context menu. You can add, modify or remove menu items. This is a dependency property.

Namespace: DevExpress.Xpf.Spreadsheet.Menu

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

NuGet Package: DevExpress.Wpf.Spreadsheet

#Declaration

public ObservableCollection<IBarManagerControllerAction> Customizations { get; set; }

#Property Value

Type Description
ObservableCollection<DevExpress.Xpf.Bars.IBarManagerControllerAction>

A collection of bar actions.

#Example

The example below demonstrates how to customize the Cell context menu.

Custom context menu

View Example

<dx:ThemedWindow x:Class="WpfSpreadsheetMenuCustomization.MainWindow" mc:Ignorable="d" 
                 Title="Spreadsheet" Height="450" Width="800"
    xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfSpreadsheetMenuCustomization"
    xmlns:dxsps="http://schemas.devexpress.com/winfx/2008/xaml/spreadsheet" 
    xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars">
    <Grid>
        <dxsps:SpreadsheetControl x:Name="spreadsheetControl">
            <dxsps:SpreadsheetControl.MenuCustomizations>
                <dxsps:SpreadsheetMenuCustomization MenuType="Cell">
                    <!--Add a separator after the first three menu items.-->
                    <dxb:InsertAction Index="3">
                        <dxb:BarItemSeparator />
                    </dxb:InsertAction>
                    <!--Insert a custom menu item under the separator
                    to highlight selected cells.-->
                    <dxb:InsertAction Index="4">
                        <dxb:BarButtonItem Content="Highlight Cells" 
                                           ItemClick="HighlightCells_ItemClick" />
                    </dxb:InsertAction>
                    <!--Append a new item to the end of the context menu
                    and bind this item to the spreadsheet command.-->
                    <dxb:BarButtonItem Command="{Binding RelativeSource={RelativeSource Self}, Mode=OneWay, 
                        Path=(dxsps:SpreadsheetControl.Spreadsheet).CommandProvider.MergeAndCenterCells}" 
                        Content="Merge Cells" />
                    <!--Change the Copy item's content.-->
                    <dxb:UpdateAction ElementName="{x:Static dxsps:DefaultBarItemNames.PopupMenuItem_Copy}" 
                                      PropertyName="Content" 
                                      Value="Copy Cells" />
                    <!--Remove the Insert Comment item from the menu.-->
                    <dxb:RemoveAction ElementName="{x:Static dxsps:DefaultBarItemNames.PopupMenuItem_InsertComment}" />
                    <!--Remove the Hyperlink item from the menu.-->
                    <dxb:RemoveAction ElementName="{x:Static dxsps:DefaultBarItemNames.PopupMenuItem_InsertHyperlink}" />
                </dxsps:SpreadsheetMenuCustomization>
            </dxsps:SpreadsheetControl.MenuCustomizations>
        </dxsps:SpreadsheetControl>
    </Grid>
</dx:ThemedWindow>

Handle the Highlight Cells item’s ItemClick event to highlight selected cells in yellow.

private void HighlightCells_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
{
    // Fill selected cells with the yellow color. 
    spreadsheetControl.Selection.FillColor = System.Drawing.Color.Yellow;
}
See Also