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

}

最佳答案 这里的问题是FlowDocument的DocumentPaginator没有对BlockUIContainer进行分页,即它不会破坏多个页面中的BlockUIContainer内容.我在这里回答了类似的问题
Print flowdocument scroll viewer on multiple pages

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

或者有一种非正统的方式来打印本文http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls中解释的整个Control(Visual)

控制转换为位图,然后根据要打印的页面大小进行切割.

谢谢

点赞