How to print a formatted page containing a ListBox or GridView

Printing a document using WinRT:

1) Continue tracking if there is more data or text data to print on a formatted page.

This can be done using RichTextBlock and RichTextBlockOverflow, as shown below:

 <RichTextBlock Foreground = "Black" x: Name = "textContent" FontSize = "18" Grid.Row = "1" Grid.ColumnSpan = "2" OverflowContentTarget = "{Binding ElementName = firstLinkedContainer}" 
 IsTextSelectionEnabled = "True" TextAlignment = "Left" FontFamily = "Segoe UI" VerticalAlignment = "Top" HorizontalAlignment = "Left">

 </RichTextBlok>

 <RichTextBlockOverflow x: Name = "firstLinkedContainer" OverflowContentTarget = "{Binding ElementName = continuationPageLinkedContainer}" Grid.Row = "2" Grid.Column = "0" />



But how to track a ListBox so that it can contain multiple pages of data to print on a formatted page?

Suppose this formatted XAML page contains Grid.Row = "0" and Grid.row = "1":

1) Grid.Row = "0": Header for customer information
2) Grid.Row = "1": Body for Order transaction

ListBox will be added to the Canvas object with Opacity = "0"
The ListBox will be populated with data from the local database.

Questions:

What control is required for tracking if the ListBox has more print data?

 <StackPanel x: Name = "header" Grid.Row = "0" Grid.ColumnSpan = "2" Height = "60" Visibility = "Collapsed">
        <StackPanel Orientation = "Horizontal">
          <RichTextBlock Foreground = "Black" FontSize = "20" TextAlignment = "Left" FontFamily = "Segoe UI">
           <Paragraph> Order- Printing test
           </RichTextBlock>
        </StackPanel>
  </StackPanel>

 <StackPanel x: Name = "Body" Grid.Row = "1" Margin = "100,30,106,148">

    <ListBox Height = "500" x: Name = "Lbx1" Margin = "30.3.84.0">
       <ListBox.ItemTemplate>
          <DataTemplate>
              <StackPanel Orientation = "Horizontal">

                    <TextBlock FontSize = "20" Margin = "10,10,30,10">
                     <Run Text = "name:" /> <Run Text = "{Binding ItemName}" />
                    </TextBlock>

                    <TextBlock FontSize = "20" Margin = "30,10,10,10">
                     <Run Text = "code:" /> <Run Text = "{Binding ItemCode}" />
                     </TextBlock>

                     <TextBlock FontSize = "20" Margin = "10">
                      <Run Text = "Price:" /> <Run Text = "{Binding Price}" />
                     </TextBlock>

                    <TextBlock FontSize = "20" Margin = "10">
                     <Run Text = "Quantity:" /> <Run Text = "{Binding Quantity}" />
                    </TextBlock>
               </StackPanel>

             </DataTemplate>
         </ListBox.ItemTemplate>
      </ListBox>            

 </StackPanel>

+4
source share

Source: https://habr.com/ru/post/1501264/


All Articles