32

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

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

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

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

4

3 回答 3

26

是的,这行得通,我在 wpf 项目中使用 WindowsFormsHost 来包装 ReportViewer。

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

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

在视图中,我使用 ContentPresenter 通过绑定到包含 WindowsFormsHost 的属性来显示它。

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

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

保重,
马丁

于 2010-02-18T18:47:28.343 回答
24

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

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

于 2009-05-08T00:17:07.080 回答
3

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

因此,如果您将 ReportViewer 放在一个单独的 Windows-Forms-Window 中,您可以避免使用 WindowsFormsHost,您可以使用 ShowDialog 从 WPF 窗口打开该窗口。

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

于 2014-12-16T08:06:45.603 回答