WPF Documents


A flow document is represented by the FlowDocument element. It provides us with a rich set of classes for creating, viewing, modifying, packaging and storing high-quality documents. That’s great. Let’s go back and compare other elements. WPF Documents are discussed in the book by Adam Nathan called WPF 4.5 Unleashed, published by Sams, starting on page 318.

FlowDocument is a FrameworkContentElement, the control-centric parallel to FrameworkElement. FrameworkContentElements support data binding, annimation and other WPF mechanisms, but they do not participate in WPF’s layout mechanism.

  • FlowDocument – is a FrameworkContentElement
  • TextElement – is a FrameworkContentElement

TextElement is an abstract class that represents content that can be placed inside a FlowDocument.

Displaying Flow Documents

A FlowDocument can be viewed and edited inside a RichTextBox. RichTextBox was not meant for displaying read-only documents, even though it can if the IsReadOnly property is set to true. WPF provides three additional controls for displaying read-only flow documents.

  • FlowDocumentScrollViewer – one continuous file with scrollbar
  • FlowDocumentPageViewer – pages, like Full Screen Reading mode in MS Word
  • FlowDocumentReader – combines the above two, and has text search. This is the control you get by default if you use FlowDocument as the root element in your XAML file.