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

  显示原文与译文双语对照的内容
0 0

好友们

我尝试使用实体数据模型在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>

这里有什么问题?

谢谢

时间: 原作者:

0 0

我相信问题是你在CrystalReportViewer_Loaded里面加载报告

在Window_Loaded事件中设置你的报告加载,并在CrystalReportViewer代码中移除加载的事件,如下所示:

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) { 
...
}

原作者:
...