Skip to main content

SpreadsheetControl.MenuCustomizations Property

Allows you to customize the Spreadsheet control’s context menus. This is a dependency property.

Namespace: DevExpress.Xpf.Spreadsheet

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

NuGet Package: DevExpress.Wpf.Spreadsheet

Declaration

public ObservableCollection<SpreadsheetMenuCustomization> MenuCustomizations { get; set; }

Property Value

Type Description
ObservableCollection<SpreadsheetMenuCustomization>

A collection of menu customization actions.

Remarks

Add the InsertAction, UpdateAction or RemoveAction customization actions to the SpreadsheetControl.MenuCustomizations collection to create, modify, or remove items of the Spreadsheet control’s context menus. Use the SpreadsheetMenuCustomization.MenuType property to specify the menu type you want to customize.

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;
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the MenuCustomizations 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.

See Also