Skip to end of metadata
Go to start of metadata

Remarks

A flow document is designed to "reflow content" depending on window size, device resolution, and other environment variables. It also has a number of built in features including search, viewing modes that optimize readability, and the ability to apply formatting to the flow elements. Flow document is best utilized when ease of reading is the primary document consumption scenario. In contrast, fixed document is useful when fidelity of the source content is essential. For more information about fixed document, see Document Framework Overview.

To view a flow document, it must be contained in a flow document viewer control. There are three types of flow document viewer, which are UXFlowDocumentViewer, UXFlowDocumentPageViewer, and UXFlowDocumentScrollViewer. For further information about these viewers, see the overview of each control.

The following code example shows how to author a simple FlowDocument in a UXFlowDocumentViewer.

XAML

Working with Blocks Property

The diagram below shows the element schema in FlowDocument.

Working with CustomPaginator Property, DocumentPaginator Property

FlowDocument should be contained within UXFlowDocumentViewer, UXFlowDocumentPageViewer, or UXFlowDocumentScrollViewer. All viewers have built-in printing capability which allows users to easily print the flow document. If you don't want to use the built-in capability, you can print a document programmatically.

CS

PrintDocument class will use the Print method to print the document. Print method needs two parameters, DocumentPaginator object and the document name. DocumentPaginator is an abstract base class that supports creation of multiple-page elements from a single document. By default, each FlowDocument has DocumentPaginator property that contain DocumentPaginator object for the flow document.

When FlowDocument is in page mode, the document content will flow according to the specified page configuration. If FlowDocument is in scroll mode, the document content will flow according to the available view port. In Silverlight application, you can choose a page size in the Print dialog window. In this case, the DocumentPaginator will create multiple page elements, despite of whether the FlowDocument is in page mode or scroll mode, for printing purpose with the selected page size. Unlike Silverlight application, the selected page size in the Print dialog window is not used in WPF application. If you need to specify different page size for printing purpose, it is recommended that you use custom paginator.

You can specify a custom paginator class to add custom elements for printing purpose only, such as header or footer. To learn more about how to implement custom paginator class for printing purpose, see How-to: Use Custom Paginator to Print FlowDocument.

Working with FontFamily Property, FontSize Property, FontStretch Property, FontStyle Property, FontWeight Property, Foreground Property and TextAlignment Property

Global formatting can be applied to all elements in FlowDocument by configuring it in FlowDocument object. You can set a series of font configuration, such as FontFamily, FontSize, FontStretch, FontStyleFontWeight to the document. In addition, you can use Foreground property to set the default foreground color for all document elements. You can use TextAlignment property to set default text alignment, as well as LineSpacingType and LineSpacing properties to specify the default line spacing configuration. Note that the global configuration will be overridden if there is individual configuration specified in element level.

The following code example shows a simple FlowDocument with various font formatting.

XAML

Working with LineSpacing and LineSpacingType Property

You can use LineSpacingType and LineSpacing properties to specify spacing between lines in FlowDocument elements. The following are the options of LineSpacingType property:

  • Single
    When this option is selected, there will be no spacing between the lines.
  • OneAndHalfLines
    When this option is selected, the spacing between lines will be half of the line height.
  • Double
    When this option is selected, the spacing between lines will be the same as the line height.
  • AtLeast
    When this option is selected, the line height will at least be the same with the value of LineSpacing property. For example, if LineSpacing is set to 25, the line height will at least be 25 pixel. The line height can be a larger value than 25 pixel.
  • Exactly
    When this option is selected, the line height will exactly be the same as the value of LineSpacing property. For example, if the LineSpacing is set to 25, the line height will be exactly 25 pixel. If the line height is larger than 25 pixel, the content will be clipped.
  • Multiple
    When this option is selected, the line height will use the value of LineSpacing property multiplied by 2. For example, if the LineSpacing is set to 25, the line height will be 50 pixel.

Working with PageBorderThickness Property, PageHeight Property, PageMargin Property, PagePadding Property and PageWidth Property

When FlowDocument is in page mode, you can set the default page size using PageHeight and PageWidth properties. The default page size in FlowDocument is letter size (816 px x 1056 px). You can set PagePadding property to set the padding space between the boundaries of a page and the page's content. You can set PageMargin property to set the margin space between pages. You can also set PageBorderThickness to set the border thickness for each page.

XAML

Working with Styles Property

You can specify predefined styles that can be applied to all elements in FlowDocument, using FlowDocumentStyle collection. In FlowDocumentStyle, you can specify the fundamental element formatting, such as background, foreground, font-related properties, and border. Each FlowDocumentStyle should have a name, which will be referred from the element.

XAML

Definition

public class FlowDocument : DependencyObject,

IDisposable, IDocumentPaginatorSource

Summary

The following table summarizes the members exposed in this class.

Public Constructors

FlowDocument Constructor()Initializes a new instance of the FlowDocument class.
FlowDocument Constructor(Block)Initializes a new instance of the FlowDocument class.

Public Properties

BackgroundGets or sets the Brush used to fill the background of content area.
BlocksGets or sets the top-level Block element collection of FlowDocument content.
ColumnGap 
ColumnRuleBrush 
ColumnRuleWidth 
ColumnWidth 
CustomPaginatorGets or sets custom paginator object that is used in printing process.
DocumentPaginatorGets or sets the document paginator object that is used in printing process.
FontFamilyGets or sets the preferred top-level font family for the document.
FontSizeGets or sets the top-level font size for the document.
FontStretchGets or sets the top-level font-stretching characteristics for the document.
FontStyleGets or sets the top-level font style for the document.
FontWeightGets or sets the top-level font weight for the document.
ForegroundGets or sets the Brush to apply to the text contents of the document.
InternalPageSize 
IsColumnWidthFlexible 
IsHyphenationEnabled 
IsOptimalParagraphEnabled 
LineSpacingGets or sets the custom line spacing of the element.
LineSpacingTypeGets or sets the line spacing type of the element.
MaxPageHeightGets or sets the maximum height for pages in a document.
MaxPageWidthGets or sets the maximum width for pages in a document.
MinPageHeightGets or sets the minimum height for pages in a document.
MinPageWidthGets or sets the minimum width for pages in a document.
PageBorderThicknessGets or sets the border thickness applied to pages in a document.
PageCountGets the total of pages in the document.
PageHeightGets or sets the preferred height for pages in a document.
PageMarginGets or sets a value that indicates the space between pages in a document.
PagePaddingGets or sets a value that indicates the thickness of padding space between the boundaries of a page and the page's content.
PageWidthGets or sets the preferred width for pages in a document.
StylesGets or sets the FlowDocumentStyle collection applied to a document.
TextAlignmentGets or sets a value that indicates the horizontal alignment of text content.

Fields

BackgroundPropertyIdentifies the Background dependency property.
BlocksPropertyIdentifies the Blocks dependency property.
ColumnGapPropertyIdentifies the ColumnGap dependency property.
ColumnRuleBrushPropertyIdentifies the ColumnRuleBrush dependency property.
ColumnRuleWidthPropertyIdentifies the ColumnRuleWidth dependency property.
ColumnWidthPropertyIdentifies the ColumnWidth dependency property.
FontFamilyPropertyIdentifies the FontFamily dependency property.
FontSizePropertyIdentifies the FontSize dependency property.
FontStretchPropertyIdentifies the FontStretch dependency property.
FontStylePropertyIdentifies the FontStyle dependency property.
FontWeightPropertyIdentifies the FontWeight dependency property.
ForegroundPropertyIdentifies the Foreground dependency property.
InternalPageSizePropertyIdentifies the InternalPageSize dependency property.
IsColumnWidthFlexiblePropertyIdentifies the IsColumnWidthFlexible dependency property.
IsHyphenationEnabledPropertyIdentifies the IsHyphenationEnabled dependency property.
IsOptimalParagraphEnabledPropertyIdentifies the IsOptimalParagraphEnabled dependency property.
LineSpacingPropertyIdentifies the LineSpacing dependency property.
LineSpacingTypePropertyIdentifies the LineSpacingType dependency property.
MaxPageHeightPropertyIdentifies the MaxPageHeight dependency property.
MaxPageWidthPropertyIdentifies the MaxPageWidth dependency property.
MinPageHeightPropertyIdentifies the MinPageHeight dependency property.
MinPageWidthPropertyIdentifies the MinPageWidth dependency property.
PageBorderThicknessPropertyIdentifies the PageBorderThickness dependency property.
PageHeightPropertyIdentifies the PageHeight dependency property.
PageMarginPropertyIdentifies the PageMargin dependency property.
PagePaddingPropertyIdentifies the PagePadding dependency property.
PageWidthPropertyIdentifies the PageWidth dependency property.
StylesPropertyIdentifies the Styles dependency property.
TextAlignmentPropertyIdentifies the TextAlignment dependency property.
ViewingModePropertyIdentifies the ViewingMode dependency property.

Public Methods

Dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Public Constructors

public FlowDocument()

Initializes a new instance of the FlowDocument class.

public FlowDocument(Block block)

Initializes a new instance of the FlowDocument class.

Parameters

block 

 

Public Properties

public Brush Background { get; set; }

Gets or sets the Brush used to fill the background of content area.

public BlockCollection Blocks { get; set; }

Gets or sets the top-level Block element collection of FlowDocument content.

public double ColumnGap { get; set; }

 

public Brush ColumnRuleBrush { get; set; }

 

public double ColumnRuleWidth { get; set; }

 

public double ColumnWidth { get; set; }

 

public DocumentPaginator CustomPaginator { get; set; }

Gets or sets custom paginator object that is used in printing process.

public DocumentPaginator DocumentPaginator { get; }

Gets or sets the document paginator object that is used in printing process.

public FontFamily FontFamily { get; set; }

Gets or sets the preferred top-level font family for the document.

public double FontSize { get; set; }

Gets or sets the top-level font size for the document.

public FontStretch FontStretch { get; set; }

Gets or sets the top-level font-stretching characteristics for the document.

public FontStyle FontStyle { get; set; }

Gets or sets the top-level font style for the document.

public FontWeight FontWeight { get; set; }

Gets or sets the top-level font weight for the document.

public Brush Foreground { get; set; }

Gets or sets the Brush to apply to the text contents of the document.

public Size InternalPageSize { get; set; }

 

public bool IsColumnWidthFlexible { get; set; }

 

public bool IsHyphenationEnabled { get; set; }

 

public bool IsOptimalParagraphEnabled { get; set; }

 

public double LineSpacing { get; set; }

Gets or sets the custom line spacing of the element.

public LineSpacingType LineSpacingType { get; set; }

Gets or sets the line spacing type of the element.

public double MaxPageHeight { get; set; }

Gets or sets the maximum height for pages in a document.

public double MaxPageWidth { get; set; }

Gets or sets the maximum width for pages in a document.

public double MinPageHeight { get; set; }

Gets or sets the minimum height for pages in a document.

public double MinPageWidth { get; set; }

Gets or sets the minimum width for pages in a document.

public Thickness PageBorderThickness { get; set; }

Gets or sets the border thickness applied to pages in a document.

public int PageCount { get; }

Gets the total of pages in the document.

public double PageHeight { get; set; }

Gets or sets the preferred height for pages in a document.

public Thickness PageMargin { get; set; }

Gets or sets a value that indicates the space between pages in a document.

public Thickness PagePadding { get; set; }

Gets or sets a value that indicates the thickness of padding space between the boundaries of a page and the page's content.

public double PageWidth { get; set; }

Gets or sets the preferred width for pages in a document.

public FlowDocumentStyleCollection Styles { get; set; }

Gets or sets the FlowDocumentStyle collection applied to a document.

public TextAlignment TextAlignment { get; set; }

Gets or sets a value that indicates the horizontal alignment of text content.

Fields

public static readonly DependencyProperty BackgroundProperty

Identifies the Background dependency property.

public static readonly DependencyProperty BlocksProperty

Identifies the Blocks dependency property.

public static readonly DependencyProperty ColumnGapProperty

Identifies the ColumnGap dependency property.

public static readonly DependencyProperty ColumnRuleBrushProperty

Identifies the ColumnRuleBrush dependency property.

public static readonly DependencyProperty ColumnRuleWidthProperty

Identifies the ColumnRuleWidth dependency property.

public static readonly DependencyProperty ColumnWidthProperty

Identifies the ColumnWidth dependency property.

public static readonly DependencyProperty FontFamilyProperty

Identifies the FontFamily dependency property.

public static readonly DependencyProperty FontSizeProperty

Identifies the FontSize dependency property.

public static readonly DependencyProperty FontStretchProperty

Identifies the FontStretch dependency property.

public static readonly DependencyProperty FontStyleProperty

Identifies the FontStyle dependency property.

public static readonly DependencyProperty FontWeightProperty

Identifies the FontWeight dependency property.

public static readonly DependencyProperty ForegroundProperty

Identifies the Foreground dependency property.

public static readonly DependencyProperty InternalPageSizeProperty

Identifies the InternalPageSize dependency property.

public static readonly DependencyProperty IsColumnWidthFlexibleProperty

Identifies the IsColumnWidthFlexible dependency property.

public static readonly DependencyProperty IsHyphenationEnabledProperty

Identifies the IsHyphenationEnabled dependency property.

public static readonly DependencyProperty IsOptimalParagraphEnabledProperty

Identifies the IsOptimalParagraphEnabled dependency property.

public static readonly DependencyProperty LineSpacingProperty

Identifies the LineSpacing dependency property.

public static readonly DependencyProperty LineSpacingTypeProperty

Identifies the LineSpacingType dependency property.

public static readonly DependencyProperty MaxPageHeightProperty

Identifies the MaxPageHeight dependency property.

public static readonly DependencyProperty MaxPageWidthProperty

Identifies the MaxPageWidth dependency property.

public static readonly DependencyProperty MinPageHeightProperty

Identifies the MinPageHeight dependency property.

public static readonly DependencyProperty MinPageWidthProperty

Identifies the MinPageWidth dependency property.

public static readonly DependencyProperty PageBorderThicknessProperty

Identifies the PageBorderThickness dependency property.

public static readonly DependencyProperty PageHeightProperty

Identifies the PageHeight dependency property.

public static readonly DependencyProperty PageMarginProperty

Identifies the PageMargin dependency property.

public static readonly DependencyProperty PagePaddingProperty

Identifies the PagePadding dependency property.

public static readonly DependencyProperty PageWidthProperty

Identifies the PageWidth dependency property.

public static readonly DependencyProperty StylesProperty

Identifies the Styles dependency property.

public static readonly DependencyProperty TextAlignmentProperty

Identifies the TextAlignment dependency property.

public static readonly DependencyProperty ViewingModeProperty

Identifies the ViewingMode dependency property.

Public Methods

public void Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

  • No labels