ActiveReports 7本身没有对WPF系统提供支持,不过我们可以通过WPF提供的WindowsFromHost控件来实现这一功能,通过WindowsFromHost 可以在WPF系统中使用WinForms平台的控件。所以,我们只需要将ActiveReports 7的Viewer控件通过WindowsFormHost进行宿主就可以在WPF中浏览ActiveReports 7开发出来的报表。
详细操作步骤如下:
1、在Visual Studio中创建一个WPF应用程序
2、在工程中添加一个ActiveReports 7 Section Report (code-based)类型的报表文件
3、在工程中添加一个ActiveReports 7 Page Report类型的报表文件
4、在XAML设计界面添加一个WindowsFormsHost控件
5、在XAML的后台代码中添加以下代码:
private void btnSectionRpt_Click(object sender, RoutedEventArgs e) { Invoice rpt = new Invoice(); rpt.Run(); 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); viewer1.LoadDocument(pageDocument); windowsFormsHost2.Child = viewer1; } 复制代码
源码下载:VS2010 + ActiveReports 7
- WPFAR7_Csharp.zip (40.87 K, 下载次数:6)