Training
Module
Control Variable Scope and Logic using Code Blocks in C# - Training
Use code blocks with more confidence, understanding how they impact the visibility and accessibility of both higher and lower-level constructs in your code.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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...")));
Dim flowDoc As 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);
Dim p As 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;
Dim countTopLevelBlocks As Integer = 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()
.NET Desktop feedback feedback
.NET Desktop feedback is an open source project. Select a link to provide feedback:
Training
Module
Control Variable Scope and Logic using Code Blocks in C# - Training
Use code blocks with more confidence, understanding how they impact the visibility and accessibility of both higher and lower-level constructs in your code.
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in