TextPointer.GetNextInsertionPosition Method
Returns a TextPointer to the next insertion position in the specified logical direction.
Namespace: System.Windows.Documents
Assembly: System.Windows (in System.Windows.dll)
Parameters
- direction
- Type: System.Windows.Documents.LogicalDirection
One of the LogicalDirection values that specify the logical direction in which to search for the next insertion position.
Return Value
Type: System.Windows.Documents.TextPointerA TextPointer that identifies the next insertion position in the requested direction, or null if no next insertion position can be found.
An insertion position is a position where new content may be added without breaking any semantic rules for the associated content. In practice, an insertion position is anywhere in content where a caret may be positioned. An example of a valid TextPointer position that is not an insertion position is the position between two adjacent Paragraph tags (that is, between the closing tag of the preceding paragraph and the opening tag of the next paragraph).
The following code uses the GetNextInsertionPosition method to underline the last word in the RichTextBox. This code example is part of a larger example used in the TextPointer class.
//This method underlines the last word in a RichTextBox public void UnderlineLastWord() { TextPointer EndofContent = MyRTB1.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward); TextPointer currentPointer = EndofContent.GetNextInsertionPosition(LogicalDirection.Backward); if (currentPointer == null) return; string currentChar = GetCurrentChar(MyRTB1, currentPointer, LogicalDirection.Backward); while (currentChar != " " && currentChar != "") { currentPointer = currentPointer.GetNextInsertionPosition(LogicalDirection.Backward); currentChar = GetCurrentChar(MyRTB1, currentPointer, LogicalDirection.Backward); } if (currentChar == " ") MyRTB1.Selection.Select(currentPointer.GetNextInsertionPosition(LogicalDirection.Forward), EndofContent); else MyRTB1.Selection.Select(currentPointer, EndofContent); MyRTB1.Selection.ApplyPropertyValue(Run.TextDecorationsProperty, TextDecorations.Underline); } private string GetCurrentChar(RichTextBox RTB, TextPointer pointer, LogicalDirection direction) { TextPointer nextPointer = pointer.GetNextInsertionPosition(direction); if (nextPointer != null) { RTB.Selection.Select(pointer, nextPointer); if (RTB.Selection.Text.Length != 0) return RTB.Selection.Text[0].ToString(); } return ""; }
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.