我试图打印视觉(或任何相关的)从WPF元素分页。我正在使用MVVM模式开发。
这是我的视觉布局。用户可以在其中滚动查看页面。
<ScrollViewer>
<StackPanel x:Name="Wrapper">
<StackPanel x:Name="PageOne" />
<StackPanel x:Name="PageTwo" />
</StackPanel>
</ScrollViewer>
视觉通过按钮上的命令绑定传递。
<Button Command="{Binding PrintCommand}" CommandParameter="{BindingElementName=Wrapper}"
视觉传递给打印方法。
PrintDialog newDialog = new PrintDialog();
newDialog.PrintVisual(MyVisualName, "Printing is Fun!");
我想分页这两页(和更多),也缩放到纸张的视觉,同时保持符合MVVM风格。
谢谢。
发布于 2015-03-21 00:33:58
最后我使用了Flow。
<FlowDocumentScrollViewer>
<FlowDocument x:Name="EntirePage">
<Section>
<BlockUIContainer>
</BlockUIContainer>
</Section>
</FlowDocument>
</FlowDocumentScrollViewer>
BlockUIContainer中的每个控件都是打印出来的。(要使分页工作正常,需要大量的页面大小和页边距)节/ BlockUI会自动分页-所以对我来说,第一页是一页BlockUi,第二页是另一页评论/询问更多信息
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown">
<i:InvokeCommandAction Command="{Binding PrintCommand}" CommandParameter="{Binding ElementName=EntirePage}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
我通过命令参数传递FlowDocument。
printCommand = new RelayCommand(p => PreparePrint((FlowDocument)p));
(pageVisual是通过命令param传递的流文档)
然后,在几种方法之间,我得到了;
IDocumentPaginatorSource idocument = pageVisual as IDocumentPaginatorSource;
printDialog.PrintDocument(idocument.DocumentPaginator, "Printing Machine : " + Machine.Serial);
如果你很困惑,需要帮助(就像我一样),那就不要犹豫地评论/问问题。
https://stackoverflow.com/questions/28844378
复制相似问题