[]
To load and display a report using the Viewer control in a WPF application,
Create a new a WPF application in Visual Studio.
From the Visual Studio toolbox, drag the Viewer control onto your XAML Form.
Set the viewer's Dock property to Fill to show the complete Viewer control on the Form.
In the Solution Explorer, select the report you have created and from the Properties window, set Copy to Output Directory to Copy Always.
On MainWindow.xaml, with the viewer selected, go to the Properties window and double click the Loaded event.
In the MainWindow code view that appears, add code like the following to the viewer1_loaded event to bind the report to the viewer.
Note: The viewer control name you use in your code behind must match the value of the
x:Nameattribute, defined in your XAML.For example, if your XAML contains
<Wpf:Viewer x:Name="ReportViewer" />then in your code-behind you must reference the control as:
ReportViewer
This code shows an .rdlx report being loaded, but you can use an .rpx report file as well.
ReportViewer.LoadDocument("rptSingleLayout.rdlx");ReportViewer.LoadDocument("rptSingleLayout.rdlx")The sample code below shows how to load your RDLX-based report directly from a snapshot. See Working with Snapshots for details.
ReportViewer.LoadDocument(@"C:\Temp\Report1.rdlx-snap"); ReportViewer.LoadDocument("C:\Temp\Report1.rdlx-snap") To load a snapshot from a page document, use the code as follows.
using System.IO;
var doc = PageDocument.LoadSnapshot(new FileInfo("C:\\Temp\\Report1.rdlx-snap"));
ReportViewer.LoadDocument(doc);Imports System.IO
' Create a FileInfo object for the snapshot file
Dim snapshotFile As New FileInfo("C:\Temp\Report1.rdlx-snap")
' Load the snapshot into a PageDocument
Dim doc = PageDocument.LoadSnapshot(snapshotFile)
' Show the document in the viewer control
ReportViewer.LoadDocument(doc)var report = new MySectionReport();
ReportViewer.LoadDocument(report);Dim report As New MySectionReport()
ReportViewer.LoadDocument(report)var xmlReport = new SectionReport();
xmlReport.LoadLayout(new FileInfo(@"C:\Reports\Invoice.rpx"));
ReportViewer.LoadDocument(xmlReport);Dim xmlReport As New SectionReport()
xmlReport.LoadLayout(New FileInfo("C:\Reports\Invoice.rpx"))
ReportViewer.LoadDocument(xmlReport)Note: If Page/RDLX report is selected from dropdown of Source property (containing relative path), 'Copy to Output Directory' for selected report should be set as 'Copy always/Copy if newer' otherwise error "Could not find file ... " appears on loading WPF Viewer.
Caution: In WPF Viewer control, previewing code-based Section reports using Source and SourceFormat properties is not supported.
Note:
Refer to the LoadDocument method to see other ways to load a report in WPF Viewer.
We can set report for WPFViewer directly on XAML file and load the report in WPF Viewer using Source and SourceFormat properties.
To avoid evaluation banners appearing at run time, license your ActiveReports WPF Application project. You can find information on licensing in License Your ActiveReports.