【问题标题】:Using MS ReportViewer in WPF在 WPF 中使用 MS ReportViewer
【发布时间】:2010-10-24 16:04:55
【问题描述】:

我即将开始在 WPF 应用程序中使用 MS ReportViewer,方法是将 ReportViewer 放置在 WindowsFormsHost 中。

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

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

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

【问题讨论】:

    标签: wpf reportviewer


    【解决方案1】:

    是的,这行得通,我在 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

    保重,
    马丁

    【讨论】:

    • 我必须为 windowsFormsHost 定义一个高度,否则,我没有看到 reportViewer。
    【解决方案2】:

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

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

    【讨论】:

    • 感谢马特的反馈,很高兴知道我正朝着正确的方向前进。
    • 它工作得很好,但请记住,您不能在 xaml Window 标记中添加属性 AllowsTransparency="True"。如果你说的是真的,WindowsFormsHost 就会消失。
    【解决方案3】:

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

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

    那么您也可以在设计时使用 ReportViewer。

    【讨论】:

      猜你喜欢
      • 2011-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-04
      • 2015-07-01
      • 2023-01-26
      相关资源
      最近更新 更多