我能够在WPF应用中使用Report Viewer(使用Microsoft.ReportViewer.VS2015.WinForms包)打印报告。但是我在代码背后做了这件事。我将此post作为参考。我现在关注的是,是否可以将视图中的报表查看器绑定到视图模型?
以下是我目前的实施情况。但我想保留WPF的MVVM方式。
这是我的观点:MainWindow.xaml
<Grid>
<WindowsFormsHost>
<rv:ReportViewer x:Name="reportViewer"/>
</WindowsFormsHost>
</Grid>
以下是打印报告的代码隐藏:MainWindow.xaml.cs
DataTable openReports = GetReports();
ReportDataSource dataSource = new ReportDataSource("DataSet1", openReports);
PageSettings ps = new PageSettings();
ps.Landscape = true;
ps.Margins = new Margins(50, 50, 50, 50);
ps.PaperSize = new PaperSize("A4", 827, 1170);
ps.PaperSize.RawKind = (int)PaperKind.A4;
this.reportViewer.SetPageSettings(ps);
this.reportViewer.LocalReport.ReportPath = "Reports.rdlc";
this.reportViewer.LocalReport.DataSources.Clear();
this.reportViewer.LocalReport.DataSources.Add(dataSource);
this.reportViewer.RefreshReport();
GetReports(); //method for getting data from database to populate reports.
谢谢! :)
编辑: 我所做的是将内容呈现器绑定到我的View模型中的Windows窗体主机,它运行正常!感谢您的投入!