TextRange myRange = new TextRange(myRichTextBox.Document.ContentStart, myRichTextBox.Document.ContentEnd); // Load the first 10 characters of the range into another TextRange object TextRange subRange = new TextRange(myRange.Start, myRange.Start.GetPositionAtOffset(10)); subRange.Load(Stream, DataFormats.Text);
TextRange myRange = new TextRange(myRichTextBox.Selection.Start, myRichTextBox.Selection.End); // Load the selected text into another TextRange object TextRange selectedRange = new TextRange(myRange.Start, myRange.End); selectedRange.Load(Stream, DataFormats.Text);In this example, we create a TextRange object that spans the selected text in a RichTextBox control. We then create a new TextRange object that contains the same text, and load it using the Load method. The package library for this method is System.Windows.Controls.Ribbon.dll.