* Suggestion/warning fixes for US-1889327. * Updated H2s. * Minor content edit. * Review edits. * Minor edits. * Update dotnet-desktop-guide/framework/wpf/advanced/localization-attributes-and-comments.md Co-authored-by: Andy (Steve) De George <[email protected]>
3.8 KiB
title, ms.date, ms.custom, description, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | ms.custom | description | dev_langs | helpviewer_keywords | ms.assetid | ||||
|---|---|---|---|---|---|---|---|---|---|---|
| How to: Manipulate a FlowDocument through the Blocks Property | 03/30/2017 | devdivchpfy22 | Learn how to manipulate a FlowDocument through the Blocks property. |
|
|
cbb7291e-3f1b-433e-9e16-f4d93ced14e8 |
How to: Manipulate a FlowDocument through the Blocks Property
These examples demonstrate some of the more common operations that can be performed on a xref:System.Windows.Documents.FlowDocument through the xref:System.Windows.Documents.FlowDocument.Blocks%2A property.
Create a new FlowDocument
The following example creates a new xref:System.Windows.Documents.FlowDocument and then appends a new xref:System.Windows.Documents.Paragraph element to the xref:System.Windows.Documents.FlowDocument.
[!code-csharpFlowDocumentSnippets#_FlowDocumentBlocksAdd] [!code-vbFlowDocumentSnippets#_FlowDocumentBlocksAdd]
Create a new Paragraph element
The following example creates a new xref:System.Windows.Documents.Paragraph element and inserts it at the beginning of the xref:System.Windows.Documents.FlowDocument.
[!code-csharpFlowDocumentSnippets#_FlowDocumentBlocksInsert] [!code-vbFlowDocumentSnippets#_FlowDocumentBlocksInsert]
Get top-level Block elements
The following example gets the number of top-level xref:System.Windows.Documents.Block elements contained in the xref:System.Windows.Documents.FlowDocument.
[!code-csharpFlowDocumentSnippets#_FlowDocumentBlocksCount] [!code-vbFlowDocumentSnippets#_FlowDocumentBlocksCount]
Delete the last Block element
The following example deletes the last xref:System.Windows.Documents.Block element in the xref:System.Windows.Documents.FlowDocument.
[!code-csharpFlowDocumentSnippets#_FlowDocumentBlocksRemoveLast] [!code-vbFlowDocumentSnippets#_FlowDocumentBlocksRemoveLast]
Clear all the Block contents
The following example clears all of the contents (xref:System.Windows.Documents.Block elements) from the xref:System.Windows.Documents.FlowDocument.
[!code-csharpFlowDocumentSnippets#_FlowDocumentBlocksClear] [!code-vbFlowDocumentSnippets#_FlowDocumentBlocksClear]