
Understanding and Defining Flow Documents
When designing a flow document, keep in mind that the content will dynamically fix itself within the
container. FlowDocument is the key type. It defines a display area to compose a flow document. This type
extends FrameworkContentElement, which is-a ContentElement. Like the FrameworkElement base
class, this base class supports data binding, animation, and so on but does not support WPF’s layout scheme.
Flow documents can contain two type of ‘content elements’, which (like the FlowDocument itself) extend
the ContentElement parent class:
• Block Elements: Used to group together related content in the flow document. Example classes
include List, Paragraph, Section, and Table.
• In-line Elements: In-line elements such as Run, Span, LineBreak, Figure, and Floater are
nested inside a block element.
The ContentElement base class provides block and in-line elements with basic formatting capabilities, the
same type of capabilities found within FrameworkElement:
• Foreground and Background properties.
• Numerous font properties (FontSize, FontWeight, and more) and tooltip support.
• Support for WPF styles via the Style property.
Block elements extend the Block class, which adds additional support to derived types, such as the following:
• Margins and padding.
• Border settings (BorderThickness, BorderBrush).
• Text alignment settings.
When you wish to build a flow document in XAML, simply define a <FlowDocument> element. Here is a
Window that defines a FlowDocument as its Content value. Notice that this simple definition automatically
results in a UI frame that enables various ways to view the content, including support for searching and
zooming.
<Window x:Class = "FunWithDocuments.Window1"
xmlns = "http://schemas.microsoft.com/winfx/2006/
xaml/presentation"
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "My Flow Document App" Height = "334" Width = "481">
<!-- This type holds flow docs! -->
<FlowDocument>
</FlowDocument>
</Window>
In reality, a FlowDocument cannot be set as a Content value. When a FlowDocument is the direct content of
a Page or Window as seen previously, the FlowDocumentReader is used as the container by default. This is
the entity that enabled the document UI seen here (search, zooming, and so on).
It is always a good idea to wrap your <FlowDocument> in a fitting container as this allow you to place it
within a panel container. Here is a reworking of the previous window:
<Window x:Class = "FunWithDocuments.Window1"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
Title = "My Flow Document App" Height = "334" Width = "481">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height = "66*" />
<RowDefinition Height = "230*" />
</Grid.RowDefinitions>
<Label FontSize = "14" Background = "PowderBlue">
This is my flow document app!</Label>
<!-- This type holds flow docs. -->
<FlowDocumentReader Grid.Row = "1" BorderBrush = "Black"
BorderThickness = "2">
<FlowDocument>
</FlowDocument>
</FlowDocumentReader>
</Grid>
</Window>
You can also wrap a FlowDocument within additional containers to alter how the document is displayed:
• FlowDocumentScrollViewer: No zoom, search, or paging UI but just one long, continuous file
with a scroll bar.
<FlowDocumentScrollViewer Grid.Row="1" BorderBrush="Black"
BorderThickness="2">
<FlowDocument>
</FlowDocument>
</FlowDocumentScrollViewer>
• FlowDocumentPageViewer: Displays document page by page, only one page at a time.
<FlowDocumentPageViewer Grid.Row="1" BorderBrush="Black"
BorderThickness="2">
<FlowDocument>
</FlowDocument>
</FlowDocumentPageViewer>
By default, the FlowDocumentScrollView, FlowDocumentPageViewer, and FlowDocumentReader types
allow selection and copying of data. If you wish to have a read-only block of data, set the
IsSelectionEnabled property to false.
Flow Documents
Table of Contents
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials
Services