TOC

The community is working on translating this tutorial into Tamil, but it seems that no one has started the translation process for this article yet. If you can help us, then please click "More info".

Rich Text controls:

Introduction to WPF Rich Text controls

In other UI frameworks like WinForms, displaying large amounts of richly formatted text has been somewhat of a problem. Sure, you could load a file into a RichTextBox or you could create a WebBrowser object and load a local or remote web page, but specifying larger amounts of rich text in design-time wasn't really possible. It seems that Microsoft wanted to remedy that in WPF and even go beyond just simple viewing of the text.

The FlowDocument does indeed render rich text, and that even includes images, lists and tables, and elements can be floated, adjusted and so on, and using a FlowDocument, you can specify rich text in design-time as if it were HTML (thanks to XAML) and have it rendered directly in your WPF application.

The FlowDocument doesn't stand alone. Instead, it uses one of several built-in wrappers, which controls how the FlowDocument is laid out and whether the content can be edited by the user or not. WPF includes three controls for rendering a FlowDocument in read-only mode, which all has easy support for zooming and printing:

FlowDocumentScrollViewer - the simplest wrapper around a FlowDocument, which simply displays the document as one long document of text which you can scroll in.

FlowDocumentPageViewer - this wrapper will automatically split your document into pages, which the user can navigate back and forth between.

FlowDocumentReader - a combination of the FlowDocumentScrollViewer and the FlowDocumentPageViewer, which will let the user decide between the two rendering modes. It also offers the ability AND the interface to search in the document.

The FlowDocument is normally read-only, but put it inside of a RichTextBox control (described later in this tutorial) and you can now edit the text, much like in real word processors like Microsoft Word.

Read on through the next chapters, where we'll discuss all the wrappers that you can use with a FlowDocument, both read-only and editable. After that, we'll look into all of the possibilities you have when creating rich documents using the FlowDocument, including tables, lists, images and much more.


This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!