如何使用实体数据模型在 WPF C# 中加载水晶报表

本文关键字:加载 水晶 报表 WPF 何使用 实体 数据模型 | 更新日期: 2023-09-27 18:32:07

伙计们

我尝试使用实体数据模型在WPF窗口中加载水晶报表,但它没有加载,如何加载它?

我使用了本教程,但我的环境是VS2012

http://www.c-sharpcorner.com/UploadFile/nipuntomar/crystal-report-viewer-in-wpf-part-1/

这是我的代码:

 using CrystalDecisions.CrystalReports.Engine;
 using CrystalDecisions.Shared;
 private void crystalReportsViewer1_Loaded(object sender, RoutedEventArgs e)
    {
        ReportDocument report = new ReportDocument();
        report.Load("CrystalReport1.rpt");
        using (cvmakerEntities1 db = new cvmakerEntities1())
        {
            report.SetDataSource(from c in db.cvs
             select new {c.Full_Name,c.Address,c.E_Mail,c.Activities,c.Birth_Day,c.Courses,c.Education,c.Experience,c.Gender,c.Mobile,c.Nationality,c.Occuptional_Field,c.Personnal_Website,c.photo,c.Skills,c.Tele});
        }
        crystalReportsViewer1.ViewerCore.ReportSource = report;
    } 

这是 XML 设计器中的代码

<Window x:Class="CV_Maker.Report"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:my="clnamespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
    Title="Report" Height="800" Width="800">
<Grid>
    <my:CrystalReportsViewer HorizontalAlignment="Left" Name="crystalReportsViewer1"
                             VerticalAlignment="Top" Height="769" Width="792" Loaded="crystalReportsViewer1_Loaded" />
</Grid>

这里有什么问题?

谢谢

如何使用实体数据模型在 WPF C# 中加载水晶报表

我相信

问题是您在CrystalReportViewer_Loaded内加载报告

如文章所述Window_Loaded事件中设置报表加载,并删除 CrystalReportViewer 的 xaml 代码中的已加载事件:

1) 删除加载的属性:

<my:CrystalReportsViewer HorizontalAlignment="Left" Name="crystalReportsViewer1"
                         VerticalAlignment="Top" Height="769" Width="792" Loaded="crystalReportsViewer1_Loaded" />

2) 添加窗口加载事件:

<Window xmlns:Viewer="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer" ... Loaded="Window_Loaded">

2) 重命名 xaml 中的事件.cs

private void crystalReportsViewer1_Loaded(object sender, RoutedEventArgs e)

private void Window_Loaded(object sender, RoutedEventArgs e) { 
...
}