在 WPF 中使用 MS ReportViewer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/837625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:23:10  来源:igfitidea点击:

Using MS ReportViewer in WPF

wpfreportviewer

提问by Mitch

I'm about to start using the MS ReportViewer in a WPF application by placing the ReportViewer in a WindowsFormsHost.

我将通过将 ReportViewer 放在 WindowsFormsHost 中来开始在 WPF 应用程序中使用 MS ReportViewer。

Is this the correct approach? What is the best way of designing the reports as you cannot use the ReportViewer at design time in a WindowsFormsHost.

这是正确的方法吗?设计报告的最佳方法是什么,因为您无法在设计时在 WindowsFormsHost 中使用 ReportViewer。

Is it best to create an RDL report in SQL Server and then convert it to an RDLC or maybe to create a new Winforms app to create an RDLC file in a WinForms framework and then copy it to the WPF app.

最好在 SQL Server 中创建 RDL 报告,然后将其转换为 RDLC,或者创建一个新的 Winforms 应用程序以在 WinForms 框架中创建一个 RDLC 文件,然后将其复制到 WPF 应用程序。

I will need to filter the reports via dropdowns so there's that aspect to consider too. If anyone out there is already using ReportViewer in WPF I would appreciate some feedback on the best approach.....Many thanks.

我需要通过下拉列表过滤报告,所以也需要考虑这个方面。如果有人已经在 WPF 中使用 ReportViewer,我将不胜感激关于最佳方法的一些反馈......非常感谢。

采纳答案by Matt Hamilton

We've definitely had success just using the WindowsFormsHost. I haven't been involved in creating the RDLC files themselves, but I believe they were designed (as you say) in a WinForms project and then copied across.

仅使用 WindowsFormsHost 就肯定取得了成功。我没有参与创建 RDLC 文件本身,但我相信它们是在 WinForms 项目中设计的(如您所说),然后被复制。

Note that if you don't need local reports you can use a WPF Frame control and point it at the URL of the server-based report (it renders it like a web browser would). This works really well for us too.

请注意,如果您不需要本地报告,您可以使用 WPF Frame 控件并将其指向基于服务器的报告的 URL(它像 Web 浏览器一样呈现它)。这对我们来说也非常有效。

回答by mdk

Yes, that works, I am using the WindowsFormsHost in a wpf project to wrap the ReportViewer.

是的,这有效,我在 wpf 项目中使用 WindowsFormsHost 来包装 ReportViewer。

In the ViewModel I am creating the WindowsFormsHost and the ReportViewer:

在 ViewModel 中,我正在创建 WindowsFormsHost 和 ReportViewer:

WindowsFormsHost windowsFormsHost = new WindowsFormsHost();
reportViewer = new ReportViewer();
windowsFormsHost.Child = reportViewer;
this.Viewer = windowsFormsHost

and in the View I am using a ContentPresenter to display it, by binding to the Property that holds the WindowsFormsHost.

在视图中,我使用 ContentPresenter 来显示它,方法是绑定到保存 WindowsFormsHost 的属性。

 <ContentPresenter Content="{Binding Viewer}" ...

We're using the Business Intelligence Studio (which is an Visual Studio 2008 with templates for editing reports) for report creation. http://msdn.microsoft.com/en-us/library/ms173767.aspx

我们正在使用 Business Intelligence Studio(这是一个带有用于编辑报告的模板的 Visual Studio 2008)来创建报告。http://msdn.microsoft.com/en-us/library/ms173767.aspx

Take care,
Martin

保重,
马丁

回答by csname1910

Please note that you can use both WPF-Windows and Windows-Form-Windows in the same application.

请注意,您可以在同一应用程序中同时使用 WPF-Windows 和 Windows-Form-Windows。

So you can avoid using WindowsFormsHost if you put the ReportViewer in a seperate Windows-Forms-Window that you open from your WPF-Window with ShowDialog.

因此,如果将 ReportViewer 放在使用 ShowDialog 从 WPF 窗口打开的单独 Windows 窗体窗口中,则可以避免使用 WindowsFormsHost。

Then you can use the ReportViewer also at design time.

然后您也可以在设计时使用 ReportViewer。