Skip to main content

Customize Report Designer Commands and Keyboard Shortcuts

  • 4 minutes to read

This document describes how to customize commands and keyboard shortcuts available in the Report Designer.

Customize Report Designer Commands

The Report Designer provides various built-in commands to open, create, save and close report documents as well as manage report elements. Most of end-user actions in the Report Designer trigger the corresponding commands.

The ReportDesignerCommands class provides access to the Report Designer commands.

The following example demonstrates how to override Report Designer command handlers. To do this, create a custom command provider by inheriting from the ReportDesignerCommands class, override required members and assign this provider instance to the Designer’s Commands property.

View Example: Reporting for WPF - How to Override the Report Designer Command Handlers

Imports System.Diagnostics
Imports System.Windows
Imports DevExpress.Xpf.Reports.UserDesigner

Namespace T461334

    ''' <summary>
    ''' Interaction logic for MainWindow.xaml
    ''' </summary>
    Public Partial Class MainWindow
        Inherits Window

        Public Sub New()
            Me.InitializeComponent()
            Me.designer.Commands = New CustomDesignerCommands()
            AddHandler Loaded, AddressOf Me.MainWindow_Loaded
        End Sub

        Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Me.designer.OpenDocument(New SampleReport())
        End Sub
    End Class

    Public Class CustomDesignerCommands
        Inherits ReportDesignerCommands

        Protected Overrides Sub SaveDocumentAs()
            Call Debug.WriteLine("CustomDesignerCommands.SaveDocumentAs")
            MyBase.SaveDocumentAs()
        End Sub
    End Class
End Namespace

Customize Report Designer Hot Keys

The Report Designer has default hot keys, which execute corresponding commands when being pressed. You can unregister all available keyboard shortcuts or a specific shortcut by calling the ReportDesigner.UnregisterHotKeys and ReportDesigner.UnregisterHotKey methods, respectively.

To register a custom key combination in the Report Designer, use the ReportDesigner.RegisterHotKey method. If the specified combination already exists, it will be overridden.

The sample below illustrates how to customize the default hot keys of the Report Designer both in XAML and in code.

View Example: Reporting for WPF - How to Customize Keyboard Shortcuts

Imports DevExpress.XtraReports.UI
Imports System.Windows
Imports System.Windows.Input
Imports DevExpress.Mvvm

Namespace T461248
    ''' <summary>
    ''' Interaction logic for MainWindow.xaml
    ''' </summary>
    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
            AddHandler Loaded, AddressOf MainWindow_Loaded
        End Sub

        Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Dim viewModel = New MainWindowViewModel(New SampleReport())
            DataContext = viewModel

            designer.RegisterHotKey(Key.OemTilde, ModifierKeys.Control, Function() viewModel.TestCommand, Nothing)
        End Sub
    End Class

    Public Class MainWindowViewModel
        Inherits ViewModelBase

        Private privateReport As XtraReport
        Public Property Report() As XtraReport
            Get
                Return privateReport
            End Get
            Private Set(ByVal value As XtraReport)
                privateReport = value
            End Set
        End Property
        Private privateTestCommand As ICommand
        Public Property TestCommand() As ICommand
            Get
                Return privateTestCommand
            End Get
            Private Set(ByVal value As ICommand)
                privateTestCommand = value
            End Set
        End Property

        Public Sub New(ByVal report As XtraReport)
            Me.Report = report
            TestCommand = New DelegateCommand(AddressOf RunTestCommand)
        End Sub

        Private Sub RunTestCommand()
            GetService(Of IMessageBoxService)().ShowMessage("Test command.")
        End Sub
    End Class
End Namespace