The requested page is not available for the requested platform. You are viewing the content for Default platform.

Customize Context Menus in the Report Designer

  • 3 min to read

This document demonstrates how to customize a context menu of a report and its elements in the Report Designer by removing standard context menu items and adding custom ones.

The Report Designer exposes the ReportDesigner.ContextMenuCustomizationActions property, which specifies a collection of actions used to customize the context menu of report elements. These actions allow you to remove existing context menu items or add new items for all report elements in a centralized way or for certain report elements (e.g., for label controls, report parameters or the detail band).

Supported Elements

Using the ContextMenuCustomizationActions property, you can modify the context menu of the following elements.

Remove Existing Context Menu Items

To remove a context menu item, add a RemoveAction object with an appropriate element name to the ContextMenuCustomizationActions collection. To identify context menu items by their names, use fields of the DefaultContextMenuItemNames class.

In this case, the specified item will be removed from context menus of all report elements that provide it. To customize the context menu of certain report elements (e.g., labels, tables, group header bands or a report), define a container name using special fields of the DefaultContextMenuItemNames class. These fields contain the ContextMenu postfix in their names.

The code snippet below demonstrates how to delete the Cut context menu command of labels and the Properties context menu command of all report elements.

...
<dxrud:ReportDesigner.ContextMenuCustomizationActions>
    <dxb:RemoveAction ContainerName="{x:Static dxrud:DefaultContextMenuItemNames.LabelContextMenu}" 
                      ElementName="{x:Static dxrud:DefaultContextMenuItemNames.Cut}"/>
    <dxb:RemoveAction ElementName="{x:Static dxrud:DefaultContextMenuItemNames.Properties}"/>
    ...
</dxrud:ReportDesigner.ContextMenuCustomizationActions>
...

Add New Context Menu Items

To add a new item to the context menu of all report elements, add an InsertAction object to the ContextMenuCustomizationActions collection. If you want to add a menu command to report elements of a specific type, additionally specify an appropriate container name.

This example shows how to add a new About context menu command and a separator item to labels.

...
<dxrud:ReportDesigner.ContextMenuCustomizationActions>
    ...    
    <dxb:InsertAction ContainerName="{x:Static dxrud:DefaultContextMenuItemNames.LabelContextMenu}" 
                      Index="0">
        <dxb:InsertAction.Element>
            <dxb:BarButtonItem  Glyph="{dx:DXImage Image=index_16x16.png}" Content="About" 
                                ItemClick="bAbout_ItemClick"/>
        </dxb:InsertAction.Element>
    </dxb:InsertAction>

    <dxb:InsertAction ContainerName="{x:Static dxrud:DefaultContextMenuItemNames.LabelContextMenu}" 
                      Index="1">
        <dxb:InsertAction.Element>
            <dxb:BarItemLinkSeparator/>
        </dxb:InsertAction.Element>
    </dxb:InsertAction>
</dxrud:ReportDesigner.ContextMenuCustomizationActions>
...

Then, handle the BarItem.ItemClick event of the added item as shown below.

private void bAbout_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
    MessageBox.Show("About Window", "About");
}

Get the Result

Run the application to see the result.

WpfDesigner_CustomContextMenu

Complete Code

<Window xmlns:dxrud="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesigner"  
        x:Class="CustomizeContextMenus.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
        xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <dxrud:ReportDesigner x:Name="reportDesigner">
        <dxrud:ReportDesigner.ContextMenuCustomizationActions>
            <dxb:RemoveAction ContainerName="{x:Static dxrud:DefaultContextMenuItemNames.LabelContextMenu}" 
                              ElementName="{x:Static dxrud:DefaultContextMenuItemNames.Cut}"/>
            <dxb:RemoveAction ElementName="{x:Static dxrud:DefaultContextMenuItemNames.Properties}"/>

            <dxb:InsertAction ContainerName="{x:Static dxrud:DefaultContextMenuItemNames.LabelContextMenu}" 
                              Index="0">
                <dxb:InsertAction.Element>
                    <dxb:BarButtonItem  Glyph="{dx:DXImage Image=index_16x16.png}" Content="About" 
                                        ItemClick="bAbout_ItemClick"/>
                </dxb:InsertAction.Element>
            </dxb:InsertAction>

            <dxb:InsertAction ContainerName="{x:Static dxrud:DefaultContextMenuItemNames.LabelContextMenu}" 
                              Index="1">
                <dxb:InsertAction.Element>
                    <dxb:BarItemLinkSeparator/>
                </dxb:InsertAction.Element>
            </dxb:InsertAction>
        </dxrud:ReportDesigner.ContextMenuCustomizationActions>
    </dxrud:ReportDesigner>
</Window>
See Also