Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-manipulate-flow-content-elements-through-the-inlines-property.md
T
Pooja PoojariandAndy De George caa62283b8 US-1889327: Suggestion/warning fixes for WPF. (#1314)
* 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]>
2022-02-23 10:27:19 -08:00

4.7 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 Flow Content Elements through the Inlines Property 03/30/2017 devdivchpfy22 Learn how to manipulate Flow Content Elements through the Inlines property.
csharp
vb
flow content elements [WPF], manipulating through Inlines property
documents [WPF], manipulating flow Content elements through Inlines property
Inlines property [WPF], manipulating flow Content elements
properties [WPF], Inlines [WPF], manipulating flow Content elements
510780d2-3da1-4360-8763-7054bda22ea3

How to: Manipulate Flow Content Elements through the Inlines Property

These examples demonstrate some of the more common operations that can be performed on inline flow content elements (and containers of such elements, such as xref:System.Windows.Controls.TextBlock) through the Inlines property. This property is used to add and remove items from xref:System.Windows.Documents.InlineCollection. Flow content elements that feature an Inlines property include:

These examples happen to use xref:System.Windows.Documents.Span as the flow content element, but these techniques are applicable to all elements or controls that host an xref:System.Windows.Documents.InlineCollection collection.

Create a new Span object

The following example creates a new xref:System.Windows.Documents.Span object, and then uses the Add method to add two text runs as content children of the xref:System.Windows.Documents.Span.

[!code-csharpSpanSnippets#_SpanInlinesAdd] [!code-vbSpanSnippets#_SpanInlinesAdd]

Create a new Run element

The following example creates a new xref:System.Windows.Documents.Run element and inserts it at the beginning of the xref:System.Windows.Documents.Span.

[!code-csharpSpanSnippets#_SpanInlinesInsert] [!code-vbSpanSnippets#_SpanInlinesInsert]

Get the top-level Inline elements in the Span

The following example gets the number of top-level xref:System.Windows.Documents.Inline elements contained in the xref:System.Windows.Documents.Span.

[!code-csharpSpanSnippets#_SpanInlinesCount] [!code-vbSpanSnippets#_SpanInlinesCount]

Delete the last Inline element in the Span

The following example deletes the last xref:System.Windows.Documents.Inline element in the xref:System.Windows.Documents.Span.

[!code-csharpSpanSnippets#_SpanInlinesRemoveLast] [!code-vbSpanSnippets#_SpanInlinesRemoveLast]

Clear all the Inline element content from the Span

The following example clears all of the contents (xref:System.Windows.Documents.Inline elements) from the xref:System.Windows.Documents.Span.

[!code-csharpSpanSnippets#_SpanInlinesClear] [!code-vbSpanSnippets#_SpanInlinesClear]

See also