ItemsControl:如何在多个页面上打印WrapPanel?
我正在尝试打印此内容,但只出现第一页。 例如,如果 ItemsControlCodigos 有 200 个项目,则仅显示 1 页。
这怎么能轻易做到呢?
<FlowDocumentReader Name="FlowDocumentReader1" Margin="397,85,0,0">
<FlowDocument Name="fd">
<BlockUIContainer>
<ItemsControl Name="ItemsControlCodigos" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontFamily="Tahoma" FontSize="10pt" Text="{Binding Descricao, TargetNullValue='--'}" Width="100px" />
<StackPanel Orientation="Horizontal" Width="100px">
<TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text="(" />
<TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text="{Binding id_Produto}" />
<TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text=")" />
</StackPanel>
<Button Name="buttonExcluirItem" BorderThickness="0" BorderBrush="Transparent" Background="Transparent"
VerticalAlignment="Center"
Margin="-4,-1,-1,-1"
Opacity="0.3"
ToolTip="Excluir este Item">
<Image Width="16" Height="16" />
</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</BlockUIContainer>
</FlowDocument>
</FlowDocumentReader>
C#
private void ButtonImprimir_Click(object sender, RoutedEventArgs e)
{
// 20-05-2011
PrintDialog pd = new PrintDialog();
//pd.PrintVisual(ItemsControlCodigos, "Etiquetas");
fd.PageHeight = pd.PrintableAreaHeight;
fd.PageWidth = pd.PrintableAreaWidth;
fd.PagePadding = new Thickness(50);
fd.ColumnGap = 0;
fd.ColumnWidth = pd.PrintableAreaWidth;
IDocumentPaginatorSource dps = fd;
//dps.DocumentPaginator.PageCount;
pd.PrintDocument(dps.DocumentPaginator, "flow doc");
}
I am trying to print this, but only the first page appears.
for example if ItemsControlCodigos has 200 items, only 1 page appears.
How can this be done easily?
<FlowDocumentReader Name="FlowDocumentReader1" Margin="397,85,0,0">
<FlowDocument Name="fd">
<BlockUIContainer>
<ItemsControl Name="ItemsControlCodigos" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock FontFamily="Tahoma" FontSize="10pt" Text="{Binding Descricao, TargetNullValue='--'}" Width="100px" />
<StackPanel Orientation="Horizontal" Width="100px">
<TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text="(" />
<TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text="{Binding id_Produto}" />
<TextBlock FontFamily="IDAutomationHC39M" FontSize="10pt" Text=")" />
</StackPanel>
<Button Name="buttonExcluirItem" BorderThickness="0" BorderBrush="Transparent" Background="Transparent"
VerticalAlignment="Center"
Margin="-4,-1,-1,-1"
Opacity="0.3"
ToolTip="Excluir este Item">
<Image Width="16" Height="16" />
</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</BlockUIContainer>
</FlowDocument>
</FlowDocumentReader>
C#
private void ButtonImprimir_Click(object sender, RoutedEventArgs e)
{
// 20-05-2011
PrintDialog pd = new PrintDialog();
//pd.PrintVisual(ItemsControlCodigos, "Etiquetas");
fd.PageHeight = pd.PrintableAreaHeight;
fd.PageWidth = pd.PrintableAreaWidth;
fd.PagePadding = new Thickness(50);
fd.ColumnGap = 0;
fd.ColumnWidth = pd.PrintableAreaWidth;
IDocumentPaginatorSource dps = fd;
//dps.DocumentPaginator.PageCount;
pd.PrintDocument(dps.DocumentPaginator, "flow doc");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的问题是
FlowDocument
的DocumentPaginator
不会对BlockUIContainer
进行分页,即它不会破坏BlockUIContainer
内容跨多个页面。我在这里回答了类似的问题 在多个页面上打印 flowdocument 滚动查看器简而言之,您必须创建多个 BlockUIContainer,每个 BlockUIContainer 都包含其 itemsControl。
或者本文中解释了一种打印整个控件(视觉)的非正统方法 http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls
其中控件被转换为位图,然后根据到要打印的页面大小。
谢谢
The issue here is that the
DocumentPaginator
ofFlowDocument
does not paginate theBlockUIContainer
i.e it does not break theBlockUIContainer
content across multiple pages. I have answered the similar question here Print flowdocument scroll viewer on multiple pagesIn short, you will have to create multiple BlockUIContainer each containing its itemsControl.
OR There is an unorthodox way of printing the whole Control(Visual) explained in this article http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls
where control was converted to Bitmap which was then chopped according to the pagesize to print.
Thanks