8

I have created a flowdocument and added numerous paragraphs to it programmically. Now in the I would like to be able to reset the flow document to a blank slate resulting in everything being erased.

I have looked for things like Clear, Reset, RemoveAll, Erase. Is there a method to emptying the document?

Jack
  • 241
  • 4
  • 12

2 Answers2

22

Clear the Blocks collection of the FlowDocument:

document.Blocks.Clear();

The How to: Manipulate a FlowDocument through the Blocks Property includes this example, as well as other common operations (such as inserting a new paragraph at the beginning, or deleting the last block element).

nam
  • 21,967
  • 37
  • 158
  • 332
Bradley Grainger
  • 27,458
  • 4
  • 91
  • 108
11

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

flowDoc.Blocks.Clear();

See the How to: Manipulate a FlowDocument through the Blocks Property for the above example, and FlowDocument Overview for more examples.

nam
  • 21,967
  • 37
  • 158
  • 332
gliderkite
  • 8,828
  • 6
  • 44
  • 80