WPF StoreDataSetPaginator
public class StoreDataSetPaginator : DocumentPaginator
{
private DataTable dt; // Could be wrapped with public properties that call PaginateData() when set.
private Typeface typeface;
private double fontSize;
private double margin; public StoreDataSetPaginator(DataTable dt, Typeface typeface, double fontSize, double margin, Size pageSize)
{
this.dt = dt;
this.typeface = typeface;
this.fontSize = fontSize;
this.margin = margin;
this.pageSize = pageSize;
PaginateData();
}
public override bool IsPageCountValid
{
get { return true; }
} private int pageCount;
public override int PageCount
{
get { return pageCount; }
} private Size pageSize;
public override Size PageSize
{
get
{
return pageSize;
}
set
{
pageSize = value;
PaginateData();
}
} public override IDocumentPaginatorSource Source
{
get { return null; }
} // This helper method splits the data into pages.
// In some cases you'll need to store objects representing the per-page data.
// Here, a rowsPerPage value is enough becuase every page is the same.
private int rowsPerPage; /// <summary>
/// 计算页数
/// </summary>
private void PaginateData()
{
// Create a test string for the purposes of measurement.
FormattedText text = GetFormattedText("A"); // Count the lines that fit on a page.
rowsPerPage = (int)((pageSize.Height - margin * ) / text.Height); // Leave a row for the headings
rowsPerPage -= ; pageCount = (int)Math.Ceiling((double)dt.Rows.Count / rowsPerPage);
} public override DocumentPage GetPage(int pageNumber)
{
// Create a test string for the purposes of measurement.
FormattedText text = GetFormattedText("A");
// Size columns relative to the width of one "A" letter.
// It's a shortcut that works in this example.
double col1_X = margin;
double col2_X = col1_X + text.Width * ; // Calculate the range of rows that fits on this page.
int minRow = pageNumber * rowsPerPage;
int maxRow = minRow + rowsPerPage; // Create the visual for the page.
DrawingVisual visual = new DrawingVisual(); // Initially, set the position to the top-left corner of the printable area.
Point point = new Point(margin, margin); // Print the column values.
using (DrawingContext dc = visual.RenderOpen())
{
// Draw the column headers.
Typeface columnHeaderTypeface = new Typeface(typeface.FontFamily, FontStyles.Normal, FontWeights.Bold, FontStretches.Normal);
point.X = col1_X;
text = GetFormattedText("Model Number", columnHeaderTypeface);
dc.DrawText(text, point);
text = GetFormattedText("Model Name", columnHeaderTypeface);
point.X = col2_X;
dc.DrawText(text, point); // Draw the line underneath.
dc.DrawLine(new Pen(Brushes.Black, ),
new Point(margin, margin + text.Height),
new Point(pageSize.Width - margin, margin + text.Height)); point.Y += text.Height; // Draw the column values.
for (int i = minRow; i < maxRow; i++)
{
// Check for the end of the last (half-filled) page.
if (i > (dt.Rows.Count - )) break; point.X = col1_X;
text = GetFormattedText(dt.Rows[i]["ModelNumber"].ToString());
dc.DrawText(text, point); // Add second column.
text = GetFormattedText(dt.Rows[i]["ModelName"].ToString());
point.X = col2_X;
dc.DrawText(text, point);
point.Y += text.Height;
}
}
return new DocumentPage(visual, pageSize, new Rect(pageSize), new Rect(pageSize));
} private FormattedText GetFormattedText(string text)
{
return GetFormattedText(text, typeface);
} private FormattedText GetFormattedText(string text, Typeface typeface)
{
return new FormattedText(
text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
typeface, fontSize, Brushes.Black);
} }
WPF StoreDataSetPaginator的更多相关文章
- 在WPF中使用依赖注入的方式创建视图
在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...
- MVVM框架从WPF移植到UWP遇到的问题和解决方法
MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...
- MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息
MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...
- MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信
MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...
- MVVM设计模式和WPF中的实现(四)事件绑定
MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式解析和在WPF中的实现(三)命令绑定
MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式和在WPF中的实现(二)数据绑定
MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...
- MVVM模式和在WPF中的实现(一)MVVM模式简介
MVVM模式解析和在WPF中的实现(一) MVVM模式简介 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在 ...
- 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])
常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...
随机推荐
- javaSE eclipse tomocat安装与配置
---恢复内容开始--- javaSE 下载: 第一步:百度收索jdk downlaod 下载地址:https://www.oracle.com/technetwork/ja ...
- 8个Python小Tips
原创: 金牌小编 行走在Python的江湖,那能不收藏一些锦囊妙计,今天分享给大家8个小技巧,希望在实战的时候有帮助! 01. 条件判断 condition=Trueif condition: ...
- python自动化开发-[第十三天]-javascript
今日概要 1.javascript简单语法 1.javascript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名S ...
- centos7下安装pip以及mysql等软件
1.安装pip 安装失败了的提示: No package pip available.Error: Nothing to do 解决方法: 需要先安装扩展源EPEL. EPEL(http://fedo ...
- 2、JPA-Annotation
注解放在类属性上不生效时可放在get方法上试试,原因未知 @Entity /** * @Entity 该Java类为实体类,将映射到数据库表.如声明一个实体类 Customer,它将映射到数据库中的 ...
- 163邮箱SMTP设置
如题要设置系统邮件自动发送 首先注册的网易邮箱要去开通SMTP服务,然后就是端口的设置 授权码 端口
- MyEclipse做的项目改成eclipse能用的
转至:https://blog.csdn.net/cymlancy/article/details/67634531 首先导入一个从Myeclipse导出的项目 Myeclipse项目和Eclipse ...
- [Android] Android ViewPager 中加载 Fragment的两种方式 方式(二)
接上文: https://www.cnblogs.com/wukong1688/p/10693338.html Android ViewPager 中加载 Fragmenet的两种方式 方式(一) 二 ...
- maven多模块依赖源码调试
Maven多模块项目中,通常存在摸个模块同时依赖其他多个基础模块的情况.在eclipse中使用run-jetty-run插件调试时,常常会出现找不到被依赖模块对应源码的错误提示.举个例子,模块A同时依 ...
- Hadoop 博文整理
参考文章##搭建 使用yum安装CDH Hadoop集群 http://blog.javachen.com/2013/04/06/install-cloudera-cdh-by-yum/ Ha ...