Upgrading old WPF ActiveReports Projects to ActiveReports 7 WPFViewer
ActiveReports has been in the business of providing reporting solutions to organizations and individuals alike. Throughout the years, ActiveReports has evolved and added support for various platforms like Windows Forms, Web, Silverlight, and Flash. However official support for WPF platform remained elusive until ActiveReports 7 Service Pack 1 release which now ships with a WPFViewer Control to cater the WPF developer community.
Although ActiveReports did not support the WPF platform prior to the ActiveReports 7 SP1 release; however developers who wanted to incorporate ActiveReports could do so using the WPF’s WindowsFormsHost control. This approach works quite well but it’s not something that we officially support.
If you are using ActiveReports 6 in your WPF application then the code should look something similar to the one provided below:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var viewer1 = new DataDynamics.ActiveReports.Viewer.Viewer();
var rpt = new WPFreport ();
rpt.Run();
viewer1.Document = _rpt.Document;
windowsFormsHost1.Child = viewer1;
}
If you using version of ActiveReports 7 that precedes the ActiveReports 7 Service Pack1 release in your WPF Application to load Page Reports (.rdlx) or Section Reports, then the code should look similar to the one provided below:
Old ActiveReports 7 Page Report Code:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var fileName = @"C:\\Invoice1.rdlx";
var viewer1 = new GrapeCity.ActiveReports.Viewer.Win.Viewer();
var pageReport = new GrapeCity.ActiveReports.PageReport(new FileInfo(file_name));
var pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
viewer1.LoadDocument(pageDocument);
windowsFormsHost1.Child = viewer1;
}
Old ActiveReports 7 Section Report Code:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var viewer1 = new GrapeCity.ActiveReports.Viewer.Win.Viewer();
var rpt = new WPFreport ();
rpt.Run();
viewer1.Document = _rpt.Document;
windowsFormsHost1.Child = viewer1;
}
Since ActiveReports 7 SP1 release ships with WPFViewer control, all the above code is now redundant. You can now upgrade your existing WPF projects using ActiveReports as WPF’s WindowsFormsHost control to now use WPFViewer control by the following steps:
For ActiveReports 6 Users:
Existing ActiveReports 6 users will need to upgrade to ActiveReports 7 to use the WPFViewer. The upgrade instructions are easy and they can be read from here.
After, ActiveReports 6 users have upgraded to ActiveReports 7, they need to follow the same steps that have been listed for existing ActiveReport 7 users
For Existing ActiveReports 7 Users:
- Open your existing WPF Project and open the XAML page that contains the Windows Forms Host control that is used to host the ActiveReports Viewer control.
- Remove the Windows Forms Host control from the Design View.
- From the Toolbox ActiveReports 7 tab, drag the Viewer control and drop it on the design view of the XAML page.
- Clear the old Section Report or Page Report Code that was used to show the report using the Windows Forms Host control.(refer to code snippets provided above).
- Now add the following code to bind the existing report to WPFViewer control.
ActiveReports 7 PageReport Code:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
viewer1.LoadDocument("C:Invoice1.rdlx ");
}
ActiveReports 7 SectionReport Code ( For old ActiveReports 6 users and exising ActiveReports 7 users)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
viewer1.LoadDocument(new WPFreport());
}
After, you have completed the above listed steps you are ready to run your project and see the WPFViewer in action.