Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-insert-an-element-into-text-programmatically.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

29 lines
1.4 KiB
Markdown

---
title: "How to: Insert an Element Into Text Programmatically"
ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
helpviewer_keywords:
- "Text Animation sample [WPF]"
- "elements [WPF], inserting into text"
- "inserting elements into text [WPF]"
- "TextPointer objects [WPF]"
- "text [WPF], inserting elements"
ms.assetid: 97bd950a-25ac-4e42-a311-94b6420d4136
---
# How to: Insert an Element Into Text Programmatically
The following example shows how to use two <xref:System.Windows.Documents.TextPointer> objects to specify a range within text to apply a <xref:System.Windows.Documents.Span> element to.
## Example
[!code-csharp[FlowMiscSnippets_procedural_snip#InsertInlineIntoTextExampleWholePage](~/samples/snippets/csharp/VS_Snippets_Wpf/FlowMiscSnippets_procedural_snip/CSharp/InsertInlineIntoTextExample.cs#insertinlineintotextexamplewholepage)]
[!code-vb[FlowMiscSnippets_procedural_snip#InsertInlineIntoTextExampleWholePage](~/samples/snippets/visualbasic/VS_Snippets_Wpf/FlowMiscSnippets_procedural_snip/VisualBasic/InsertInlineIntoTextExample.vb#insertinlineintotextexamplewholepage)]
The illustration below shows what this example looks like.
![A Span element applied to a range of text](./media/flow-insertelementintotextprogrammatically.png "Flow_InsertElementIntoTextProgrammatically")
## See also
- [Flow Document Overview](flow-document-overview.md)