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 逆天通用水印扩展篇~新增剪贴板系列 ...
随机推荐
- maven直接饮用jar包的写法
<dependency> <groupId>sample</groupId> <artifactId>com.sample</artifactId ...
- SpringCloud之注册中心Eureka搭建
POM: <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring ...
- SpringBoot笔记十七:热部署
目录 什么是热部署 Devtools热部署 什么是热部署 热部署,就是在应用正在运行的时候升级软件,却不需要重新启动应用. 举个例子,王者荣耀的更新有时候就是热部署,热更新,就是他提示你更新,更新40 ...
- springboot整合mybatis出现的一些问题
springboot整合mybatis非常非常的简单,简直简单到发指.但是也有一些坑,这里我会详细的指出会遇到什么问题,并且这些配置的作用 整合mybatis,无疑需要mapper文件,实体类,dao ...
- Linux下Maven私服Nexus3.x环境构建操作记录【转】
Maven介绍Apache Maven是一个创新的软件项目管理和综合工具.Maven提供了一个基于项目对象模型(POM)文件的新概念来管理项目的构建,可以从一个中心资料片管理项目构建,报告和文件.Ma ...
- 01-Unity深入浅出(一)
一. 温故而知新 在开始学习Unity框架之前,有必要温习一下 [依赖倒置原则]和[手写IOC], 因为我们框架代码的构建都是基于[依赖倒置原则]的,而Unity框架的核心思想就是IOC和DI,所以有 ...
- 016、Dockerfile 常用命令(2019-01-07 周一)
参考https://www.cnblogs.com/CloudMan6/p/6864000.html Dokcerfile常见命令 FROM 指定base镜像 MAINTAINER ...
- vue加载本地json文件
背景:做地区跟行业级联下拉选择,因为想做成可以搜索的,所以必须一次加载数据,后台有做memcache缓存,但因为数据量大,还是比较费时间,所以做成本地文件,简单记录一下 准备数据,放到static下 ...
- Kudu系列-基础
Apache Kudu 支持Insert/Update/Delete 等写操作(Kudu 随机写效率也很高, 实测对一个窄表做全字段update, 其速度达到了Insert速度的88%, 而verti ...
- 【VS2015】链接器错误link2001
昨天的D3d第一章代码自己打了一遍结果运行报错LINK2001,无法解析外部的MinMain. 解决方法: 项目[属性]→[链接器]→[系统]→[子系统(subsystem)]改为控制台或者留空也可以 ...