[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
   [Collapse]Getting Started
     Lesson 1 - Create Your First Report
     Lesson 2 - Create a Grouped Report with a Document Map
     Lesson 3 - Use Your Grid Control's Layout to Create a Report
   [Expand]Fundamental Concepts
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Lesson 1 - Create Your First Report

This tutorial will guide you through the process of creating a non-hierarchical report using the DXPrinting library for WPF. You will learn how to create a simple report based on a basic "products by categories" data source.

In this tutorial, you will also learn about the main concepts of report creation, such as creating documents by declaring data templates for different document areas, and creating printing links to lay out the data in the document. You will also learn how to embed a document preview in your WPF application to preview, print and/or export the created document, as well as simplify navigation through your document using a document map and bookmarks.

To create your first report with DXPrinting, do the following.

Expanded Create a New Project

  1. Start Microsoft Visual Studio 2012, 2013, 2015 or 2017.
  2. Create a new project by pressing CTRL+SHIFT+N. In the invoked New Project dialog, select WPF Application, enter the name of the application and click OK.

  3. Open the Toolbox panel (by pressing CTRL+ALT+X), select the DocumentPreviewControl control in the DX.18.2.Reporting tab and drop it onto the form.

    In XAML, set the Name property to preview for the created control.

    By default, the Document Preview has a Ribbon toolbar. To switch to the Bars toolbar layout or remove the toolbar, click the Document Preview's smart tag, and in the invoked actions list expand the CommandBarStyle drop-down list and select the required option.

Expanded Define the Data Source

First, define the data source that will be used to generate the document. You will then select the appropriate printing link based on the data source type.

The following code illustrates the implementation of a basic data source that can be printed with a SimpleLink. To learn about printing hierarchical data sources, see the following tutorial: Lesson 2 - Create a Grouped Report with a Document Map.

Expanded Declare Data Templates

The next step is to declare a data template in your reporting application. A data template is a XAML class that allows you to define the appearance of printed data. In DXPrinting, data templates specify which elements to use to display data in your report, as well as to evaluate the styling and alignment of these elements. For more information, see the following topic in MSDN: Data Templating Overview.

To declare data templates for various sections of your report, do the following.

  1. Declare a data template for your report header area. This template will not use data bindings, and will only contain static text.
  2. Declare a data template for the body of your report ("detail area"). To do this, use a grid with the TextEdit controls bound to the corresponding data source fields.
  3. You can add a document map to your report by specifying bookmarks for the controls bound to the Name data field.

The following code implements the functionality described above.

Expanded Create a Printing Link

  1. To generate a report document for print preview, use a printing link, and assign the declared data templates to the corresponding properties of the link. To create a report document in this tutorial, we will employ a SimpleLink, which is used to print non-hierarchical data in the most simple linear fashion.

    To create a printing link in your application, do the following.

    • Handle the Loaded event of the main window.
    • Define a SimpleLink instance and assign the previously declared data templates to the corresponding properties.
    • Handle the SimpleLink.CreateDetail event, which occurs every time a new data record is printed. In this event handler, assign the data from your data source to the currently printed record.
    • Call the LinkBase.CreateDocument method to generate the report document.
  2. The last step is to assign the link's view model to the Document Preview control declared in XAML.

    The following code implements the functionality described in this section.

Expanded View the Result

Your first report is now ready. Run the application and view the results.

Expanded See Also

Is this topic helpful?​​​​​​​