RadFlowDocument hosts flow document content and is the root element in the document elements tree. It holds a collection of Section elements.
The code from Example 1 shows how you can create a new RadFlowDocument.
Example 1: Create RadFlowDocument
RadFlowDocument document = new RadFlowDocument();
RadFlowDocument exposes properties which allow you to customize the way content is presented. The following properties are available for change:
ViewType: An enumeration which specifies how the document should be laid out when displayed. It depends on the application with which the document is opened after it has been created whether this property is respected.
Theme: Specifies the theme which is applied to the document. The document theme enables you to specify colors, fonts and a variety of graphic effects which affect the look of the whole document. More information is available here.
StyleRepository: Represents the document' StyleRepository. The repository allows to add, remove or enumerate the styles of the document.
DefaultStyle: The default styles that are used for Paragraph and Run elements. More information on default styles is available here.
HasDifferentEvenOddPageHeadersFooters: Gets or sets whether pages in this document should have different headers and footers for even and odd pages.
ListCollection: Represents the collection of Lists in the document.
CommentCollection: Represents the collection of Comments in the document.
ProtectionSettings: Corresponds to the settings that are used when the document is protected. More information is available here.
DefaultTabStopWidth: The distance between automatic TabStops.
There are different actions which you can execute with the help of the RadFlowDocument element.
You can create a RadFlowDocument from scratch and add Sections to it as follows:
Example 2: Add a Section to a RadFlowDocument
RadFlowDocument document = new RadFlowDocument(); document.Sections.AddSection();
The Sections property of the document is of type SectionCollection and allows you to add sections to the document.
Alternatively, you could create a section by passing to its constructor the document it should be associated with.
Example 3: Create a section
Section section = new Section(document);
You can merge a RadFlowDocument within another document by using the Merge() method and pass the source document as a parameter to it:
Example 4: Merge documents
Additionally, you have the opportunity to specify the MergeOptions which control the merge operation:
ConflictingStylesResolutionMode: An enumeration specifying the mode used for resolving conflicts between styles with same IDs. The possible values for ConflictingStylesResolutionMode are:
- UseTargetStyle: If a conflict between styles with the same IDs appears, the style of the target document is used.
- RenameSourceStyle: If a conflict between styles with the same IDs appears, the style of the source document is renamed and used.
Example 5: Merge documents using MergeOptions
MergeOptions mergeOptions = new MergeOptions(); mergeOptions.ConflictingStylesResolutionMode = ConflictingStylesResolutionMode.RenameSourceStyle; document.Merge(sourceDocument, mergeOptions);
RadFlowDocument exposes an UpdateFields() method which allows you to update all fields in the document. More information about fields is available here.
The snippet from Example 6 shows how all fields in a document can be updated simultaneously.
Example 6: Update all fields in a document