Updates the current selection, taking two TextPointer positions to indicate the updated selection.
Assembly: System.Windows (in System.Windows.dll)
'Declaration Public Sub Select ( _ anchorPosition As TextPointer, _ movingPosition As TextPointer _ )
A TextSelection is formed from a selection between two positions indicated by two TextPointer objects. One of these positions (indicated by anchorPosition) is fixed with respect to the selection, while the other position (indicated by movingPosition) is movable. This is similar to how a user makes a selection using the mouse or keyboard.
The actual end of the new selection may be adjusted to match any selection heuristics that are applicable to the document that contains the new current selection.
The following code uses the method to select the last word in a RichTextBox and underline it. In this example, a space character is used as the word boundary. This code example is part of a larger example used in the TextPointer class.
'This method underlines the last word in a RichTextBox Public Sub UnderlineLastWord() Dim EndofContent As TextPointer = MyRTB1.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward) Dim currentPointer As TextPointer = EndofContent.GetNextInsertionPosition(LogicalDirection.Backward) If (currentPointer Is Nothing) Then Return End If Dim currentChar As String = GetCurrentChar(MyRTB1, currentPointer, LogicalDirection.Backward) While ((currentChar <> " ") _ AndAlso (currentChar <> "")) currentPointer = currentPointer.GetNextInsertionPosition(LogicalDirection.Backward) currentChar = GetCurrentChar(MyRTB1, currentPointer, LogicalDirection.Backward) End While If (currentChar = " ") Then MyRTB1.Selection.Select(currentPointer.GetNextInsertionPosition(LogicalDirection.Forward), EndofContent) Else MyRTB1.Selection.Select(currentPointer, EndofContent) End If MyRTB1.Selection.ApplyPropertyValue(Run.TextDecorationsProperty, TextDecorations.Underline) End Sub Private Function GetCurrentChar(ByVal RTB As RichTextBox, ByVal pointer As TextPointer, ByVal direction As LogicalDirection) As String Dim nextPointer As TextPointer = pointer.GetNextInsertionPosition(direction) If (Not (nextPointer) Is Nothing) Then RTB.Selection.Select(pointer, nextPointer) If (RTB.Selection.Text.Length <> 0) Then Return RTB.Selection.Text(0).ToString End If End If Return "" End Function
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.