Export (0) Print
Expand All

TextSelection.Insert Method

Silverlight

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.

Run this sample


<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();
}


Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2015 Microsoft