Using ActiveReports 7 with WPF

ActiveReports 7 is natively not supported in the WPF environment. However it can be hosted in WPF with the help of WPF's WindowsFormsHost control which allows you to host a Windows Forms control inside WPF applications. You just need to host the ActiveReports 7 Viewer control (which is responsible for rendering the report) using the WindowsFormHost control and you can view ActiveReports 7 reports in WPF . Here are the detailed steps to view both Section and Page Based reports in WPF

  1. Create a WPF Application Project using Visual Studio.
  2. Add the ActiveReports 7 Section Reports file template (code based file or Rpx) to this project and design the report as per your requirements.
  3. Add a Page Based Report to the Project and design your reports accordingly
  4. Add the WindowsFormsHost control to XAML designer page.
  5. Add the code given below to show Page Based Reports and Section Reports in WPF using the WindowsFormsHost Control.

 GrapeCity.ActiveReports.Viewer.Win.Viewer viewer1 = new GrapeCity.ActiveReports.Viewer.Win.Viewer();  
 private void btnSectionRpt_Click(object sender, RoutedEventArgs e)  
    Invoice rpt = new Invoice();  
    viewer1.Document = rpt.Document;  
    windowsFormsHost2.Child = viewer1;  

 private void btnPageReport_Click(object sender, RoutedEventArgs e)  
    string file_name = GetPath("Invoice1.rdlx");  
    GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));  
    GrapeCity.ActiveReports.Document.PageDocument pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);  
    windowsFormsHost2.Child = viewer1;  

Refer to the attached samples for complete implementation. Download C# Sample Download VB Sample


GrapeCity Developer Tools
comments powered by Disqus