This documentation is archived and is not being maintained.

BlockCollection Class

Represents a collection of Block elements. BlockCollection defines the allowable child content of the FlowDocument, Section, ListItem, TableCell, Floater, and Figure elements.

Namespace: System.Windows.Documents
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public class BlockCollection : TextElementCollection<Block>
public class BlockCollection extends TextElementCollection<Block>
public class BlockCollection extends TextElementCollection<Block>
You cannot use this managed class in XAML.

BlockCollection creation is only permitted inside an element that owns a BlockCollection, such as a FlowDocument or TextElement. As such, a BlockCollection cannot be instantiated directly and has no default or overloaded constructor.

These examples demonstrate some of the more common operations that can be performed on flow content elements through the Blocks property. This property is used to add and remove items from BlockCollection. Flow content elements that feature a Blocks property include:

  • Figure

  • Floater

  • ListItem

  • Section

  • TableCell

These examples happen to use Section as the flow content element, but these techniques are applicable to all elements that host a flow content element collection.

The following example creates a new Section and then uses the Add method to add a new Paragraph to the Section contents.

Section secx = new Section();
secx.Blocks.Add(new Paragraph(new Run("A bit of text content...")));

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

Paragraph parx = new Paragraph(new Run("Text to insert..."));
secx.Blocks.InsertBefore(secx.Blocks.FirstBlock, parx);

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

int countTopLevelBlocks = secx.Blocks.Count;

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


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



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.