Back to Devexpress

Add a Custom Control to the Report Designer Toolbox

xtrareports-116767-desktop-reporting-wpf-reporting-end-user-report-designer-for-wpf-api-and-customization-add-a-custom-control-to-the-report-designer-toolbox.md

latest3.6 KB
Original Source

Add a Custom Control to the Report Designer Toolbox

  • Feb 02, 2024
  • 4 minutes to read

This document describes how to create a WPF project with a custom control and add the control to the WPF End-User Report Designer Toolbox.

View Example: Add a Custom Control to the End-User Report Designer Toolbox (WPF)

Create a Project and Custom Control

  1. Create a new WPF project with the Report Designer named WpfApp_CustomNumericLabel.
  2. Add a new blank report to the project.
  3. Implement a custom numeric label in a file named NumericLabel.cs :

Add the Custom Control to the Toolbox

Use the RegisterControl<T>() method to add the custom control to the Toolbox :

csharp
using DevExpress.Xpf.Reports.UserDesigner;
//..

private void reportDesigner_Loaded(object sender, RoutedEventArgs e) {
    ReportDesigner.RegisterControl<NumericLabel>();
    reportDesigner.OpenDocument(new XtraReport1());
}
vb
Imports DevExpress.Xpf.Reports.UserDesigner
'..

Private Sub reportDesigner_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ReportDesigner.RegisterControl(Of NumericLabel)()
    reportDesigner.OpenDocument(New XtraReport1())
End Sub

The added control inherits an icon from the XRLabel control.

Specify an Icon for the Custom Control

Add an .svg icon named NumericLabel.svg to the project and set the icon’s Build Action property to Embedded Resource.

Apply the ToolboxSvgImage attribute for the created custom control:

csharp
using DevExpress.Utils.Design;
//..

[ToolboxSvgImage("WpfApp_CustomNumericLabel.NumericLabel.svg, WpfApp_CustomNumericLabel")]
public class NumericLabel : XRLabel { ... }
vb
Imports DevExpress.Utils.Design
'..

<ToolboxSvgImage("WpfApp_CustomNumericLabel.NumericLabel.svg, WpfApp_CustomNumericLabel")>
Public Class NumericLabel
    Inherits XRLabel

    Private ...}

Rebuild and run the project. The control with the specified icon appears in the toolbox.

Note

We recommend you use .svg icons for custom controls. If you need to specify non-svg icons, use the RegisterControl<T>(ImageSource) method.

See Also

Use Custom Controls

Create a Custom Control Inherited From XRControl