也来一篇关于Infragistics WPF Report的使用教程 (一)
前言
Infragistics Report是一款比較灵活的报表控件, 比微软的rdlc控件至少在页面打印上, 页面的控制比較好调整.
这里使用的是Infragistics Ultimate v14.1 试用版
开发工具是Visual Studio 2013 Framework 4.0 WPF Windows应用程序.
加入报表
将XamReportViewer从左側的工具栏中拖到右側的窗口中.
<ig:XamReportViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
</ig:XamReportViewer>
系统会自己主动的加入引用, 记住这些引用,公布的时候, 把这些引用一并打包. 这样在client执行时就不会出现故障了.
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzU5ODc5MjEz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
1. 先定义一个Person的类, 实现INofifyPropertyChanged接口.
public class Person:INotifyPropertyChanged
{
#region Implement of INotifyProeprtyChanged.
public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion private string _name;
private int _age;
private byte[] _profilePhoto;
public string Name
{
get { return _name; }
set { _name = value;
OnPropertyChanged("Name");
}
} public int Age
{
get { return _age; }
set { _age = value; OnPropertyChanged("Age"); }
} public byte[] ProfilePhoto
{
get { return _profilePhoto; }
set { _profilePhoto = value; OnPropertyChanged("ProfilePhoto"); }
}
}
2. 我们再定义一个MainWindowViewModel, 用于关联MainWindow.xaml的DataContext.
在MainWindow.xaml 中我们要New出一个 MainWindowViewModel的实体, 并对实体中的属性赋值. 这样才干够将相应的參数绑定到报表中. 即MVVM模式.
public class MainWindowViewModel : INotifyPropertyChanged
{
#region Implement of INotifyProeprtyChanged. public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
} #endregion private ObservableCollection<Person> _personCollection;
private DateTime _printDateTime; public ObservableCollection<Person> PersonCollection
{
get { return _personCollection; }
set
{
_personCollection = value;
OnPropertyChanged("PersonCollection");
}
} public DateTime PrintDateTime
{
get { return _printDateTime; }
set
{
_printDateTime = value;
OnPropertyChanged("PrintDateTime");
}
}
}
创建报表
加入数据源
1. 创建报表, 安装Infragistics之后, 新加入项目的时候, 会有一项infragistics, 按图所看到的, 加入报表.
2. 创建数据源
通过Report Data Explorer工具栏, 右击, 选择 DataSource - Add new Data Source,
在后面弹出的窗体中选择"Object Data Source", 点击下一步,
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzU5ODc5MjEz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="300" height="300" alt="">
选择我们刚刚定义好的MainWindowViewModel.cs, 这里须要注意一下, 在创建编辑好MainViewModel.cs之后, 须要编译一下, 加入数据源的时候才干显示出来. 否则是不会显示的.
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzU5ODc5MjEz/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
加入參数
加入參数的相对简单, 从左側的Report Data Explorer中右击Parameter, 选择"Add Static Value List Parameter", 输入參数名称就可以.
加入完毕之后, 点击OK就可以, 然后将数据源, 參数直接拖到右側的报表区域中.
绑定參数
绑定的參数之后的代码
<ig:XamReportViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ig:XamReportViewer.RenderSettings>
<ig:ClientRenderSettings DefinitionUri="/InfragisticsReportSample;component/Person.igr">
<ig:ClientRenderSettings.DataSources>
<ig:DataSource TargetDataSource="Person" ItemsSource="{Binding PersonCollection}"/>
</ig:ClientRenderSettings.DataSources>
</ig:ClientRenderSettings>
</ig:XamReportViewer.RenderSettings>
<ig:XamReportViewer.Parameters>
<ig:Parameter ParameterName="PrintDate" ParameterValue="{Binding PrintDateTime}"/>
</ig:XamReportViewer.Parameters>
</ig:XamReportViewer>
TargetDataSource = "Person" 指的是绑定的Collection的类型为Person
ItemsSource = "{Binding PersonCollection}" 指的是绑定数据源为PersonCollection
Parametername = "PrintDate" 是指我们在报表中创建的參数名称为PrintDate, ParameterValue = {Binding PrintDateTime} 是指绑定PrintDateTime的属性.
加入数据
在创建出MainWindowViewModel的时候, 指定数据源, 就能够显示出报表了.
public MainWindow()
{
InitializeComponent(); MainWindowViewModel model = new MainWindowViewModel(); model.PersonCollection = new ObservableCollection<Person>();
model.PrintDateTime = DateTime.Now; Person p = new Person();
p.Name = "哆拉A梦";
p.Age = 99;
p.ProfilePhoto = GetByteImage("doraemon.jpg");
model.PersonCollection.Add(p); p = new Person();
p.Name = "阿拉蕾";
p.Age = 100;
p.ProfilePhoto = GetByteImage("arale.jpg");
model.PersonCollection.Add(p); this.DataContext = model;
} public byte[] GetByteImage(string imagepath)
{
FileStream fs = new FileStream(imagepath, FileMode.Open);
byte[] byData = new byte[fs.Length];
fs.Read(byData, 0, byData.Length);
fs.Close();
return byData;
}
}
最后的报表结果
也来一篇关于Infragistics WPF Report的使用教程 (一)的更多相关文章
- 【基于WPF+OneNote+Oracle的中文图片识别系统阶段总结】之篇一:WPF常用知识以及本项目设计总结
篇一:WPF常用知识以及本项目设计总结:http://www.cnblogs.com/baiboy/p/wpf.html 篇二:基于OneNote难点突破和批量识别:http://www.cnblog ...
- WPF 精修篇 Winform 嵌入WPF控件
原文:WPF 精修篇 Winform 嵌入WPF控件 首先 创建WPF控件库 这样就有了一个WPF界面 在wpf中增加界面等 在winform中增加WPFDLL 重新生成解决方案 在左侧工具栏 出现W ...
- VS2019打包WPF安装程序最新教程
VS2019打包WPF安装程序最新教程,使用Visual Studio 2019开发的WPF程序如果想要打包为安装程序,除了在VS2019找到WPF项目类库直接右键发布之外,更常用的还是将其打包为ex ...
- WPF/MVVM Quick Start Tutorial - WPF/MVVM 快速入门教程 -原文,翻译及一点自己的补充
转载自 https://www.codeproject.com/articles/165368/wpf-mvvm-quick-start-tutorial WPF/MVVM Quick Start T ...
- 大数据工具篇之Hive与MySQL整合完整教程
大数据工具篇之Hive与MySQL整合完整教程 一.引言 Hive元数据存储可以放到RDBMS数据库中,本文以Hive与MySQL数据库的整合为目标,详细说明Hive与MySQL的整合方法. 二.安装 ...
- 大数据工具篇之Hive与HBase整合完整教程
大数据工具篇之Hive与HBase整合完整教程 一.引言 最近的一次培训,用户特意提到Hadoop环境下HDFS中存储的文件如何才能导入到HBase,关于这部分基于HBase Java API的写入方 ...
- 10篇写给Git初学者的最佳教程(转)
身为网页设计师或者网页开发者的你,可能已经听说过Git这个正快速成长的版本控制系统.它由GitHub维护:GitHub是一个开放性的.存储众人代码的网站.如果你想学习如何使用Git,请参考本文.在文章 ...
- 接着上一篇 《Is WPF dead》
最近美国的PM传来消息,说微软在收集开发者的意见,会对WPF进行改进,微软会主要在1) performance 2) interop 3) touch and 4) access to WinRT A ...
- C/S C# WPF锐浪报表教程
前言:锐浪报表是一种中国式报表的报表开发工具.博主使用锐浪报表有一段时间了,积累了一些经验希望能帮助你快速掌握并使用 第一章:集成项目 首先我们先去锐浪报表官网下载并安装锐浪报表. 创建WPF应用程序 ...
随机推荐
- [Java]读取文件方法大全
1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 , byteread); } } catch (IOException ...
- iOS 怎么样给自己的app打分呢?
NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",@&quo ...
- [BILL WEI] A potentially dangerous Request.Path value was detected from the client 异常处理办法
我们在ASP.net中使用URL导向后, 我们在访问某个地址,或者打开某个系统页面的时候,就会报错误: A potentially dangerous Request.Path value was d ...
- DOM笔记(一):HTMLDocument接口
操作HTML文档的第一步就是获取对文档元素的引用,每一个元素在DOM中就是一个节点,所有的元素在DOM中构成一个节点树. 用于获取元素节点定义的方法定义于HTMLDocument接口,window.d ...
- bzoj 3091 城市旅行(LCT+数学分析)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3091 [思路] 膜Popoqqq大爷的题解 click here [代码]是坑... ...
- 一个使用微软Azure blob实现文件下载功能的实例-附带源文件
Running the sample Please follow the steps below. Step 1: Open the CSAzureServeFilesFromBlobStorage. ...
- Tkinter教程之Toplevel篇
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811341 '''Tkinter教程之Toplevel篇'''#TopLevel与Frame类 ...
- 《Genesis-3D开源游戏引擎--横版格斗游戏制作教程:简介及目录》(附上完整工程文件)
介绍:讲述如何使用Genesis-3D来制作一个横版格斗游戏,涉及如何制作连招系统,如何使用包围盒实现碰撞检测,软键盘的制作,场景切换,技能读表,简单怪物AI等等,并为您提供这个框架的全套资源,源码以 ...
- Codevs No.2144 砝码称重2
2016-05-31 22:01:16 题目链接: 砝码称重2 (Codevs No.2144) 题目大意: 给定N个砝码,求称出M的重量所需砝码最小个数 解法: 贪心 使砝码数量最小,当然是每个砝码 ...
- Varnish – 高性能http加速器
Varnish是一款高性能且开源的反向代理服务器和http加速器.与传统的Squid相比,Varnish具有性能更高.速度更快.管理更方便 等诸多优点.作者Poul-Henning Kamp是Free ...