ItemsControl:如何在多个页面上打印 WrapPanel? [英] ItemsControl: How to print WrapPanel on multiple Pages?

查看:21
本文介绍了ItemsControl:如何在多个页面上打印 WrapPanel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印此文件,但只显示第一页.例如,如果 ItemsControlCodigos 有 200 个项目,则只显示 1 页.

I am trying to print this, but only the first page appears. for example if ItemsControlCodigos has 200 items, only 1 page appears.

如何轻松做到这一点?

<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"); 

}

推荐答案

这里的问题是 FlowDocumentDocumentPaginator 没有对 BlockUIContainer 即它不会破坏跨多个页面的 BlockUIContainer 内容.我在这里回答了类似的问题 在多个页面上打印流文档滚动查看器

The issue here is that the DocumentPaginator of FlowDocument does not paginate the BlockUIContainer i.e it does not break the BlockUIContainer content across multiple pages. I have answered the similar question here Print flowdocument scroll viewer on multiple pages

简而言之,您必须创建多个 BlockUIContainer,每个都包含其 itemsControl.

In short, you will have to create multiple BlockUIContainer each containing its itemsControl.

OR 这篇文章中解释了一种打印整个控件(Visual)的非正统方式http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls

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

其中控件被转换为 Bitmap,然后根据要打印的页面大小进行切割.

where control was converted to Bitmap which was then chopped according to the pagesize to print.

谢谢

这篇关于ItemsControl:如何在多个页面上打印 WrapPanel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆