Integrating the WPF Report Viewer in .NET
This article explains the steps needed to integrate the WPF report viewer into a .NET 6+ projects.
The WPF Report Viewer can display reports generated by an Embedded Reporting engine, Telerik Reporting REST Service, or Telerik Report Server. The setup described in this article is valid for all service types unless a particular service is specified. In this case, the corresponding step or option is valid only for the specified service types.
Prerequisites:
- Visual Studio 2019 or newer
- .NET SDK 6 or newer
- WPF App (.NET 6+) project
Steps to add report viewer to a WPF .NET 6+ project
-
Add the following assembly references (available in Telerik Reporting installation
Bin
directory) or NuGet package references (available in Telerik private NuGet repository):- Telerik.Reporting
- Telerik.ReportViewer.Wpf
- Telerik.ReportViewer.Wpf.Themes
- Telerik.Windows.Controls (No XAML)
- Telerik.Windows.Controls.Input (No XAML)
- Telerik.Windows.Controls.Navigation (No XAML)
- Telerik.Windows.Data (No XAML)
- Telerik.Reporting.Services.HttpClient (Required only when the viewer is used with REST Service or Report Server)
The
Telerik.Reporting
andTelerik.Reporting.Services.HttpClient
assemblies are located in the folder%programfiles(x86)%\Progress\Telerik Reporting 2024 Q3\Bin\netstandard2.0
.The
Telerik.ReportViewer.Wpf
andTelerik.ReportViewer.Wpf.Themes
assemblies can be found in%programfiles(x86)%\Progress\Telerik Reporting 2024 Q3\Bin
. Select the net6.0-windows, or net7.0-windows subfolder depending on the exact framework used.In case Telerik UI for WPF is used only for the report viewer, you may reference the Telerik UI for WPF assemblies available with Telerik Reporting. They are internally unlocked for the WPF Report Viewer but can only be used with the report viewer. The Telerik UI for WPF assemblies are located in
%programfiles(x86)%\Progress\Telerik Reporting 2024 Q3\Bin\WpfViewerDependencies
. Select the Net6 or Net7 subfolder depending on the exact framework used.The WPF ReportViewer is built with the latest official release of Telerik UI for WPF. In this way, we provide trouble-free upgrades for most of the users. This means that you can use the latest version of Telerik UI for WPF in your project and report viewer.
The Telerik UI for WPF assemblies may have a greater version (service pack or internal build) than the one targeted by the WPF report viewer control. In this case, you need to add assembly binding redirects (see the Binding Redirects topic).
We recommend using NuGet packages. In this case, the
Telerik.ReportViewer.Wpf
package will add Telerik.Reporting and all its dependencies automatically. If you prefer to add the Telerik Reporting assemblies as references, you need to add also all the Telerik.Reporting dependencies manually. This includes but may not be limited to the following packages:- Microsoft.Extensions.Configuration
- Microsoft.Extensions.Configuration.Json
- Microsoft.Extensions.Configuration.Binder
- SQLitePCLRaw.bundle_green
If you need to add also the external dependencies of Telerik.Reporting as assembly references, it would be necessary to include all their dependencies manually.
-
Merge the required theme resources:
-
to the application resources in the
App.xaml
:<Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/System.Windows.xaml" /> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.xaml" /> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.Input.xaml" /> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.Navigation.xaml" /> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.ReportViewer.Wpf.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
-
or alternatively to the resources of the Window with the viewer:
<Window x:Class="WpfApplication1.ViewerWindow.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Window.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/System.Windows.xaml" /> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.xaml" /> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.Input.xaml" /> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.Windows.Controls.Navigation.xaml" /> <ResourceDictionary Source="/Telerik.ReportViewer.Wpf.Themes;component/Themes/Fluent/Telerik.ReportViewer.Wpf.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Window.Resources> <Grid> <!--Initialize the Report Viewer here--> </Grid> </Window>
-
-
Add the following namespaces to the target Window declaration:
xmlns:tr="http://schemas.telerik.com/wpf" xmlns:telerikControls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" xmlns:telerikReporting="clr-namespace:Telerik.Reporting;assembly=Telerik.Reporting"
-
Add the WPF Report Viewer declaration to the target Window and set the proper UriReportSource.Uri relative path.
-
When using an Embedded Reporting engine:
Reference a descriptive report definition (TRDP or TRDX report) from a local folder, or type report definition (CS or VB report) from a report library project. For example, add a new folder named Reports in the application main folder, copy your TRDP reports there, and reference one of them. Don't forget to set their property 'Copy to Output Directory' to 'Copy always' or 'Copy if newer':
<tr:ReportViewer Grid.Row="1" x:Name="ReportViewer1" HorizontalAlignment="Stretch"> <tr:ReportViewer.ReportSource> <telerikReporting:UriReportSource Uri="Reports\MyReportName.trdp"> <telerikReporting:ReportSource.Parameters> <telerikReporting:Parameter Name="ParameterName_01" Value="ParameterValue_01"/> <telerikReporting:Parameter Name="ParameterName_02" Value="ParameterValue_02"/> </telerikReporting:ReportSource.Parameters> </telerikReporting:UriReportSource> </tr:ReportViewer.ReportSource> </tr:ReportViewer>
-
When using a Telerik Reporting REST Service:
The reports get rendered server-side and need to be accessible by the service. For that reason, you need to reference a descriptive report definition (TRDP or TRDX report) from a folder accessible by the service, or type report definition (CS or VB report) from a report library project that is accessible by the service.
<tr:ReportViewer Grid.Row="1" x:Name="ReportViewer1" HorizontalAlignment="Stretch" ReportEngineConnection="engine=RestService;uri=http://localhost:59654/api/reports;timeout=100;keepClientAlive=True"> <tr:ReportViewer.ReportSource> <telerikReporting:UriReportSource Uri="MyReportName.trdp"> <telerikReporting:ReportSource.Parameters> <telerikReporting:Parameter Name="ParameterName_01" Value="ParameterValue_01"/> <telerikReporting:Parameter Name="ParameterName_02" Value="ParameterValue_02"/> </telerikReporting:ReportSource.Parameters> </telerikReporting:UriReportSource> </tr:ReportViewer.ReportSource> </tr:ReportViewer>
With the above setting, the REST Service running on
http://localhost:59654/api/reports
will look for the report named "MyReportName.trdp" in the folder specified as an argument of the UriReportSourceResolver constructor. -
When using a Telerik Report Server:
The reports will be rendered by the Report Server. For that reason, you need to reference a descriptive report definition (TRDP or TRDX report) that is hosted on the server.
With the above setting, the Report Server running on<tr:ReportViewer Grid.Row="1" x:Name="ReportViewer1" HorizontalAlignment="Stretch" ReportEngineConnection="engine=ReportServer;uri=http://yourreportserver:83/;username=yourusername;password=yourpassword"> <tr:ReportViewer.ReportSource> <telerikReporting:UriReportSource Uri="MyCategory/MyReportName.trdp" /> <telerikReporting:ReportSource.Parameters> <telerikReporting:Parameter Name="ParameterName_01" Value="ParameterValue_01"/> <telerikReporting:Parameter Name="ParameterName_02" Value="ParameterValue_02"/> </telerikReporting:ReportSource.Parameters> </telerikReporting:UriReportSource> </tr:ReportViewer.ReportSource> </tr:ReportViewer>
http://yourreportserver:83
will look for the report named "MyReportName.trdp" in the category "MyCategory". Note that you need to provide a valid username and password so that the viewer can log in successfully, or have the guest user enabled in the Report Server.
-