我正在尝试打印一个UIelement
的卷轴,或者任何多重卷轴。
我继承自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>
为什么不打印第二页,第三页和第四页?