实施DocumentPaginator时,空白页 [英] Blank pages when implementing DocumentPaginator
本文介绍了实施DocumentPaginator时,空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现这样一个分页程序:
I'm trying to implement a Paginator like this:
public class MyPaginator : DocumentPaginator{
// ommitting details...
public override DocumentPage GetPage(int pageNumber) {
DocumentPage page = new DocumentPage(canvas);
return page;
}
}
它编译,它运行,但页面是空白(白色)。在'画布'是System.Windows.Controls.Canvas的一个实例。
It compiles, it runs, but the page is blank (white). the 'canvas' is an instance of System.Windows.Controls.Canvas.
当我把它放在一个屏幕上的容器状的ScrollViewer它呈现完美。
When I put it in a on-screen container like ScrollViewer it renders perfectly.
XpsDocument _xpsDocument = CreateXpsDoc(myPaginatorInstance);
这是工作的唯一的事情就是页面的大小设置为画布的大小。 ?我想什么
The only thing that is working is that the page's size is set to the size of the canvas. What am I missing?
推荐答案
我会回答我自己滚草(再次):
I'll answer my own tumbleweed (again):
public override DocumentPage GetPage(int pageNumber) {
Canvas container = new Canvas();
container.Children.Add(canvas);
double scaleX = pageSize.Width / canvas.Width;
double scaleY = pageSize.Height / canvas.Height;
container.RenderTransform = new ScaleTransform(scaleX, scaleY);
container.Width = PageSize.Width;
container.Height = PageSize.Height;
container.Measure(PageSize);
container.Arrange(new Rect(new Point(0, 0), PageSize));
Rect contentBox = new Rect(PageSize);
return new DocumentPage(container, PageSize, contentBox, contentBox);
}
这篇关于实施DocumentPaginator时,空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文