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的更多相关文章

  1. 在WPF中使用依赖注入的方式创建视图

    在WPF中使用依赖注入的方式创建视图 0x00 问题的产生 互联网时代桌面开发真是越来越少了,很多应用都转到了浏览器端和移动智能终端,相应的软件开发上的新技术应用到桌面开发的文章也很少.我之前主要做W ...

  2. MVVM框架从WPF移植到UWP遇到的问题和解决方法

    MVVM框架从WPF移植到UWP遇到的问题和解决方法 0x00 起因 这几天开始学习UWP了,之前有WPF经验,所以总体感觉还可以,看了一些基础概念和主题,写了几个测试程序,突然想起来了前一段时间在W ...

  3. MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息

    MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...

  4. MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信

    MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...

  5. MVVM设计模式和WPF中的实现(四)事件绑定

    MVVM设计模式和在WPF中的实现(四) 事件绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  6. MVVM模式解析和在WPF中的实现(三)命令绑定

    MVVM模式解析和在WPF中的实现(三) 命令绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  7. MVVM模式和在WPF中的实现(二)数据绑定

    MVVM模式解析和在WPF中的实现(二) 数据绑定 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在WPF中 ...

  8. MVVM模式和在WPF中的实现(一)MVVM模式简介

    MVVM模式解析和在WPF中的实现(一) MVVM模式简介 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 MVVM模式解析和在 ...

  9. 逆天通用水印支持Winform,WPF,Web,WP,Win10。支持位置选择(9个位置 ==》[X])

    常用技能:http://www.cnblogs.com/dunitian/p/4822808.html#skill 逆天博客:http://dnt.dkil.net 逆天通用水印扩展篇~新增剪贴板系列 ...

随机推荐

  1. opencv: 线性拟合

    opencv提供了fitline函数用于直线拟合,原型为: C++: void fitLine(InputArray points, OutputArray line, int distType, d ...

  2. django 跨域解决方案

    使用django-cors-headers模块 github:https://github.com/ottoyiu/django-cors-headers 官方文档中有详细说明 简要配置 1.安装 p ...

  3. go tcp

    TCP编程 1.客户端和服务器 2.服务端的处理流程 监听端口 接收客户端的链接 创建goroutine,处理该链接 3.客户端的处理流程 建立与服务端的链接 进行数据收发 关闭链接 服务端代码 pa ...

  4. OS + Linux RedHat 6.3 QA

    s 问题1:could not open session 解决办法 https://blog.csdn.net/qq_40809549/article/details/82658720 解决1: 配置 ...

  5. Matlab2017A破解版安装详细图文教程(附破解补丁) 64位

    摘录网址:http://www.jb51.net/softjc/543170.html MATLAB2017a安装教程: 1.下载并解压本站提供的MATLAB2017a破解版安装包,载入右键解压或者使 ...

  6. WebRequest/HttpWebRequest/HttpRequest/WebClient/HttpClient的区别

    1.WebRequest和HttpWebRequest WebRequest 的命名空间是: System.Net ,它是HttpWebRequest的抽象父类(还有其他子类如FileWebReque ...

  7. [NIO-4]选择器

    选择器 最后,我们探索一下选择器.由于选择器内容比较多,所以本篇先偏理论地讲一下,后一篇讲代码,文章也没有什么概括.总结的,写到哪儿算哪儿了,只求能将选择器写明白,并且将一些相对重要的内容加粗标红. ...

  8. [JDK8] Optional

    我们知道 Java 8 增加了一些很有用的 API, 其中一个就是 Optional. 如果对它不稍假探索, 只是轻描淡写的认为它可以优雅的解决 NullPointException 的问题, 于是代 ...

  9. JMeter:Dashboard Report自动生成测试报告的巧用和避坑

    官网地址查阅:http://jmeter.apache.org/usermanual/generating-dashboard.html 最近在压测过程中使用 Generating Report Da ...

  10. jquery中$.post()方法的简单实例

    在jqery中有这样一个方法,$.post()下面就这个方法做一个简单的实例: jQuery.post( url, [data], [callback], [type] ) :使用POST方式来进行异 ...