Share via


How to: Manipulate a FlowDocument through the Blocks Property

These examples demonstrate some of the more common operations that can be performed on a FlowDocument through the Blocks property.

Example

The following example creates a new FlowDocument and then appends a new Paragraph element to the FlowDocument.

            Dim flowDoc As New FlowDocument(New Paragraph(New Run("A bit of text content...")))
            flowDoc.Blocks.Add(New Paragraph(New Run("Text to append...")))
FlowDocument flowDoc = new FlowDocument(new Paragraph(new Run("A bit of text content...")));
flowDoc.Blocks.Add(new Paragraph(new Run("Text to append...")));

The following example creates a new Paragraph element and inserts it at the beginning of the FlowDocument.

            Dim p As New Paragraph(New Run("Text to insert..."))
            flowDoc.Blocks.InsertBefore(flowDoc.Blocks.FirstBlock, p)
Paragraph p = new Paragraph(new Run("Text to insert..."));
flowDoc.Blocks.InsertBefore(flowDoc.Blocks.FirstBlock, p);

The following example gets the number of top-level Block elements contained in the FlowDocument.

            Dim countTopLevelBlocks As Integer = flowDoc.Blocks.Count
int countTopLevelBlocks = flowDoc.Blocks.Count;

The following example deletes the last Block element in the FlowDocument.

            flowDoc.Blocks.Remove(flowDoc.Blocks.LastBlock)
flowDoc.Blocks.Remove(flowDoc.Blocks.LastBlock);

The following example clears all of the contents (Block elements) from the FlowDocument.

            flowDoc.Blocks.Clear()
flowDoc.Blocks.Clear();

See Also

Tasks

How to: Manipulate a Table's Row Groups through the RowGroups Property

How to: Manipulate a Table's Columns through the Columns Property

How to: Manipulate a Table's Row Groups through the RowGroups Property