本章只讲解xaml部分,其余都和winform下一样
1.xaml代码
<Window x:Class="RDLC.WPF.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" Loaded="Window_Loaded" Closed="Window_Closed" Title="MainWindow" Height="350" Width="525"> <WindowsFormsHost Name="windowsFormsHost"> <rv:ReportViewer x:Name="reportView" /> </WindowsFormsHost> </Window>
2.后台代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Microsoft.Reporting.WinForms; namespace RDLC.WPF { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { //代码区域 this.reportView.RefreshReport(); } private void Window_Closed(object sender, EventArgs e) { this.reportView.LocalReport.Dispose(); this.reportView.LocalReport.ReleaseSandboxAppDomain(); } } }
3.DLL引用
MainWindow.xaml:
System.Windows.Forms
WindowsFormsIntegration (.NET 4.0 才有,直接在程序集里面搜索)
MainWindow.xaml.cs:
Microsoft.ReportViewer.Common.dll、 Microsoft.ReportViewer.ProcessingObjectModel.dll、 Microsoft.ReportViewer.WebForms.dll和Microsoft.ReportViewer.WinForms.dll
注意:本次测试的Microsoft.ReportViewer的dll为版本号为11.0,试过使用9.0的,但是this.reportView.LocalReport.ReleaseSandboxAppDomain() 无法使用。
4.报表的工具栏
操作方法:在工具栏选择或取消相应的属性
例:不显示刷新按钮和导出按钮
<rv:ReportViewer x:Name="reportView" ShowRefreshButton="False" ShowExportButton="False" />
时间: 2024-11-05 17:28:48