ItemsControl:如何在多个页面上打印WrapPanel?

时间:2011-05-21 18:16:30

标签: wpf xaml

我正在尝试打印此内容,但只显示第一页。 例如,如果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"); 

}

1 个答案:

答案 0 :(得分:3)

此处的问题是DocumentPaginator的{​​{1}}没有对FlowDocument进行分页,即它不会破坏多个页面中的BlockUIContainer内容。我在这里回答了类似的问题Print flowdocument scroll viewer on multiple pages

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

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

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

由于