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. (string stoi 栈)leetcode682. Baseball Game

    You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 ...

  2. windows server 2008 远程连接

    1.win2008如何开启远程桌面 原文:https://zhidao.baidu.com/question/745350052927250652.html 正常的开启操作: 在桌面上右点" ...

  3. 降维方法PCA与SVD的联系与区别

    在遇到维度灾难的时候,作为数据处理者们最先想到的降维方法一定是SVD(奇异值分解)和PCA(主成分分析). 两者的原理在各种算法和机器学习的书籍中都有介绍,两者之间也有着某种千丝万缕的联系.本文在简单 ...

  4. 面向对象【day07】:析构函数(六)

    二.析构函数 一.概述 析构函数,第一次听说这个函数的名称,那这个函数到底是干嘛的呢?什么才是析构函数呐? 定义:在实例销毁的时候调用的函数 二.析构函数定义 2.1 定义 1 2 3 4 5 6 7 ...

  5. KMP算法的next[]数组通俗解释

    原文:https://blog.csdn.net/yearn520/article/details/6729426 我们在一个母字符串中查找一个子字符串有很多方法.KMP是一种最常见的改进算法,它可以 ...

  6. bzoj千题计划319:bzoj2865: 字符串识别(后缀自动机 + 线段树)

    https://www.lydsy.com/JudgeOnline/problem.php?id=2865 同上一篇博客 就是卡卡空间,数组改成map #include<map> #inc ...

  7. git步骤

    1.New一个Repositories 2.拿到这个仓库的URL 3.git clone https://github.com/zhuobo/new.git 4.进入到clone下来的文件夹,然后gi ...

  8. Scrapy基础02

    一.start_requests def start_requests(self): cls = self.__class__ if method_is_overridden(cls, Spider, ...

  9. Nginx负载均衡session会话保持方法

    负载均衡时,为了保证同一用户session会被分配到同一台服务器上,可以使用以下方法: 1.使用cookie 将用户的session存入cookie里,当用户分配到不同的服务器时,先判断服务器是否存在 ...

  10. 30. Spring Boot ActiveMQ

    1.引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...