Windows Presentation Foundation includes FixedDocument and FlowDocument which are used to display the documents to the user in a nice manner. Mainly FixedDocument and FlowDocuments are used to display XPS files. In this article we will take a different route and create a FixedDocument using a custom collection.

Introduction:

Windows Presentation Foundation includes FixedDocument and FlowDocument which are used to display the documents to the user in a nice manner. Mainly FixedDocument and FlowDocuments are used to display XPS files. In this article we will take a different route and create a FixedDocument using a custom collection.

Creating a Customer Entity:

Our first task is to create a Customer entity object. Take a look at the Customer classimplementation below:

The Customer object consists of the FirstName and the LastName. Now, let's see how to create a custom collection of Customer objects and populate it.

Populating Customer Collection:

The following code will populate the Customer collection with some dummy data.


Now let's see the PrintSummary page which is responsible for displaying the Customer collection in a nice manner.

Here is the code behind:

And here is the XAML part of the application.

The FixedDocument contains the PageContent element which contains the FixedPage element. The ListView contains the GridView control which is used to display the collection in a well formatted way. If you try to switch to the design mode you will get the following error:

Property 'Pages' does not support values of type 'PageContent'.

Don't worry this is a BUG in Visual Studio WPF designer. It is documented here. Hopefully, it will be fixed in Visual Studio 2010 release.

Now, when you run it you will get the following result:



Conclusion:

FixedDocument is mainly designed to support XPS formatted pages but you can also make it work when displaying custom collections. In the future articles we will look at the FlowDocument which is used to display multiple pages.

[Download Sample]