In one of the previous articles we looked at the FixedDocument. You can check out the article here. One of the limitations of the FixedDocument was that it can only display a limited amount of data. This means that if you are trying to display 200 rows and FixedDocument can only support 190 of them then 10 of your bottom rows will be truncated. The FlowDocument solves this problem by providing multiple pages to fit all the rows. In this article we will see how to use a FlowDocument to display a generic collection.


Introduction:

In one of the previous articles we looked at the FixedDocument. You can check out the article here. One of the limitations of the FixedDocument was that it can only display a limited amount of data. This means that if you are trying to display 200 rows and FixedDocument can only support 190 of them then 10 of your bottom rows will be truncated. The FlowDocument solves this problem by providing multiple pages to fit all the rows. In this article we will see how to use a FlowDocument to display a generic collection.

Creating a Custom Collection:

Let's first create a custom collection called Customer.



Now, let’s populate the List<Customer>.



Creating the FlowDocument:

Now it is time to create a FlowDocument. First check out the XAML code for the FlowDocument.

Let’s take a look at the XAML code.



As, you can see that there is only the declaration of the FlowDocument and there is no data inside it. This is because we are going to create the FlowDocument programmatically.

Let’s take a look at the BuildReport method which is responsible for constructing the FlowDocument.


The BuildReport method is iterating through the Customer collection and dividing them into a small group of 25. This means we are going to display 25 rows on a single page of the FlowDocument. Next we create a GridView control and populate it with data and finally add it to the parent ListView control.

The InlineUIContainer is used to populate the FlowDocument with WPF controls.

Now, if you run the application you will see the following result.



And here is the screenshot when we browsed to a different page.



Conclusion:

In this article we learned how to use the FlowDocument to display a generic collection. FlowDocument should be used when the number of rows are not able to fixed on a single page.