我正在尝试打印一个滚动条 aUIelement
或任何多页的东西。
我继承自DocumentPaginator
,它打印,它甚至打印正确数量的页面。
问题是它会一遍又一遍地打印第一页。
这是我的分页器:
public class MyPaginator : DocumentPaginator {
ScrollViewer _printStuff;
public MyPaginator(ScrollViewer document, PaperSize pageSize) {
_printStuff = document;
_pageSize.Height = 100; //pageSize.Height;
_pageSize.Width = 100; //pageSize.Width;
}
public override DocumentPage GetPage(int pageNumber) {
_printStuff.ScrollToVerticalOffset((PageSize.Height * pageNumber));
_printStuff.UpdateLayout();
DocumentPage dp = new DocumentPage(_printStuff);
return dp;
}
public override bool IsPageCountValid {
get { return true; }
}
private int _pageCount;
public override int PageCount {
get {
if (_pageCount == 0) {
this.ComputePageCount();
}
return _pageCount;
}
}
private Size _pageSize;
public override Size PageSize {
get {
return _pageSize;
}
set {
_pageSize = value;
}
}
public override IDocumentPaginatorSource Source {
get { return null; }
}
public override void ComputePageCount() {
//base.ComputePageCount();
var totalHeight = 0d;
if (totalHeight == 0) {
totalHeight = _printStuff.DesiredSize.Height;
}
var pc = (totalHeight / PageSize.Height);
_pageCount = (int)Math.Ceiling(pc);
}
}
这是我的调用代码:
PrinterSettings ps = new PrinterSettings();
var printDialog = new PrintDialog();
var paginator = new MyPaginator(scroller, ps.DefaultPageSettings.PaperSize);
printDialog.PrintDocument(paginator, "My Receipt");
这是我的用户控件:
<UserControl x:Class="TestVBS.Views.PrintTest2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300" Name="myBox">
<ScrollViewer Name="scroller">
<Grid Name="layout">
<StackPanel>
<Button Content="Button" HorizontalAlignment="Left" Margin="94,31,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
<TextBlock>HEllow </TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>HEllow</TextBlock>
<TextBlock>adsfas</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
<TextBlock>BBBBBBBBBBBBBBBBBBBB</TextBlock>
<TextBlock>CCCCCCCCCCCCCCCCCCC</TextBlock>
</StackPanel>
</Grid>
</ScrollViewer>
为什么它不打印第二、第三和第四页?