Insert Method
Collapse the table of content
Expand the table of content

TextSelection.Insert Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Inserts or replaces the content at the current selection as a TextElement.

Namespace:  System.Windows.Documents
Assembly:  System.Windows (in System.Windows.dll)

public void Insert(
	TextElement element
)

Parameters

element
Type: System.Windows.Documents.TextElement
The TextElement to be inserted.

This method inserts the content at the current position if there no selection or an empty selection. If there is a selection, this method replaces the current selection with the content.

The following example uses the Insert method to insert a Run element into the RichTextBox.


<RichTextBox Name="MyRTB1" Width="150" Height="30" Margin="5"/>
<Button Click="MyButton1_Click" Content="Insert Text" Height="23" Name="MyButton1" Width="75" />



//Change the current selection.   
private void BoldInsertedText()
{
    Run MyRun = new Run();
    MyRun.Text = "New inserted text";
    MyRTB1.Selection.Insert(MyRun);

}

private void MyButton1_Click(object sender, RoutedEventArgs e)
{
    BoldInsertedText();
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2017 Microsoft