On a previous Windows Forms application, I used the ReportViewer control to display the output of local SQL Server Reporting Services (SSRS) reports in my application. Unfortunately, there is no native WPF Report Viewer control with similar functionality and there will not be one in .Net 4.0 (according to Jamie Rodriguez at Microsoft). Anyway, the workaround is to use the WinForms ReportViewer control within WPF. Below is the code that I used. I had two WPF Windows that I was working with Windows1.xaml and ReportViewer.xaml. The ReportViewer Window is where I wanted the output of the report to go. The name of the report file was rptLocations.rdlc.
// Here is the link where I found the code for this routine (Thanks Sayor!):
// Add References: Microsoft.ReportVIewer.Common, Microsoft.ReportViewer.WInForms.
// Add Using statements
// Get report data
// Create instance of WindowsFormsHost to integrate the report viewer control with the WPF form.
ObservableCollection<BELocation> locationList = new ObservableCollection<BELocation>();
locationList = objLocation.GetAllLocations();
WindowsFormsHost host = new WindowsFormsHost();
// Create instance of Report Viewer Control
Microsoft.Reporting.WinForms.ReportViewer reportViewer = new Microsoft.Reporting.WinForms.ReportViewer();
// Create instance of ReportViewer.xaml Window. This window will contain the output of the report.
Window win = new ReportViewer();
// Specifying local processing mode for the ReportViewer
reportViewer.ProcessingMode = ProcessingMode.Local;
// Specifying the location of the report definition file. Use the command below, if you set "Copy to Output Directory" property to one of the
// copy options (Copy Always, Copy if newer) for the rptLocations.rdlc file.
//reportViewer.LocalReport.ReportPath = "rptLocations.rdlc";
// reportViewer1.LocalReport.ReportEmbeddedResource = "<application namespace>.[optional <folder>].<filename.rdlc>
reportViewer.LocalReport.ReportEmbeddedResource = "StagichSoftwareConsulting.WPF_LineOfBusiness.rptLocations.rdlc";
// Create a new ReportDataSource with the name of the DataSource and the object that is to be used as the DataSource
ReportDataSource ds = new ReportDataSource("BELocation", locationList);
// Add the ReportDataSource to the DataSoure of the ReportViewer
// Causes the current report in the Report Viewer to be processed and rendered.
// Sets the child control hosted by the WindowsFormsHost element.
host.Child = reportViewer;
// Add the WindowsFormsHost element to the Grid in the ReportViewer.xaml
Grid rGrid = (Grid) win.FindName("gridReportViewer");