FlowDocument.Blocks Property

Gets the top-level Block elements of the contents of the FlowDocument.

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

'Declaration
Public ReadOnly Property Blocks As BlockCollection
'Usage
Dim instance As FlowDocument 
Dim value As BlockCollection 

value = instance.Blocks
<object>
  <BlockCollection .../>
</object>

Property Value

Type: System.Windows.Documents.BlockCollection
A BlockCollection containing the Block elements that make up the contents of the FlowDocument.

Use the BlockCollection returned by this property to enumerate or manipulate contents of a FlowDocument.

Top-level child elements contained in a FlowDocument must be derived from Block. Valid top-level child elements include the following:

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

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

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.

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.

int countTopLevelBlocks = flowDoc.Blocks.Count;

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

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

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

flowDoc.Blocks.Clear();

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft