This documentation is archived and is not being maintained.

FlowDocument.Blocks Property

Gets a BlockCollection containing the top-level Block elements that comprise the contents of the FlowDocument.

Namespace: System.Windows.Documents
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public BlockCollection Blocks { get; }
/** @property */
public BlockCollection get_Blocks ()

public function get Blocks () : BlockCollection

<object>
  <BlockCollection .../>
</object>

Property Value

A BlockCollection containing the Block elements that comprise the contents of the FlowDocument. This property has no default value.

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:

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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Show: