xtrareports-116765-desktop-reporting-wpf-reporting-end-user-report-designer-for-wpf-api-and-customization-customize-context-menus-in-the-report-designer.md
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.
Important
Customization options described in this help topic are available to owners of DevExpress WPF, DXperience, or Universal subscription (subscriptions that include DevExpress WPF UI Controls). The DevExpress Reporting Subscription does not support UI customization in Report Viewer or End-User Report Designer.
Refer to the following help topic for information on subscription options: Installation - Subscriptions that Include Reporting Components.
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).
Using the ContextMenuCustomizationActions property, you can modify the context menu of the following elements.
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>
...
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");
}
Private Sub bAbout_ItemClick(sender As Object, e As DevExpress.Xpf.Bars.ItemClickEventArgs)
MessageBox.Show("About Window", "About")
End Sub
Run the application to see the result.
Tip
Online Example : WPF End-User Report Designer - How to customize context menus in the Report Designer
<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>
using System.Windows;
namespace CustomizeContextMenus {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
private void bAbout_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
MessageBox.Show("About Window", "About");
}
private void Window_Loaded(object sender, RoutedEventArgs e) {
reportDesigner.OpenDocument(new XtraReport1());
}
}
}
Imports System.Windows
Namespace CustomizeContextMenus
''' <summary>
''' Interaction logic for MainWindow.xaml
''' </summary>
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub bAbout_ItemClick(ByVal sender As Object, ByVal e As DevExpress.Xpf.Bars.ItemClickEventArgs)
MessageBox.Show("About Window", "About")
End Sub
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
reportDesigner.OpenDocument(New XtraReport1())
End Sub
End Class
End Namespace
See Also