4

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

}
Erik Schierboom
  • 16,301
  • 10
  • 64
  • 81
Tony
  • 16,527
  • 15
  • 80
  • 134

1 Answers1

3

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

In 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

Community
  • 1
  • 1
Nitin
  • 18,344
  • 2
  • 36
  • 53
  • "In short, you will have to create multiple BlockUIContainer each containing its itemsControl". I presume you mean "item" instead of "itemscontrol"? If we have a list of dynamic size, does this become impossible via XAML? The only way I can envision doing it is by inserting the BlockUIContainers dynamically via code-behind. – Kohanz Sep 17 '16 at 19:31