TextSelection Class

TextSelection Class

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

Encapsulates the selection state for the RichTextBox control.

System::Object
  System.Windows.Documents::TextSelection

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

No code example is currently available or this language may not be supported.

The TextSelection type exposes the following members.

  NameDescription
Public propertyEndGets a TextPointer that represents the end of the current selection.
Public propertyStartGets a TextPointer that represents the beginning of the current selection.
Public propertyTextGets or sets the plain text contents of the current selection.
Public propertyXamlGets or sets the XAML representation of the current selection.
Top

  NameDescription
Public methodApplyPropertyValueApplies the specified formatting property and value to the current selection.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetPropertyValueGets the value of the specified formatting property on the current selection.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInsertInserts or replaces the content at the current selection as a TextElement.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSelectUpdates the current selection, taking two TextPointer positions to indicate the updated selection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The TextSelection class represents the selection of text in the RichTextBox. This type has no public constructor, but you can access the currently selected text in the RichTextBox by using the RichTextBox::Selection property. To perform operations on the selected text, you can use the GetPropertyValue and ApplyPropertyValue methods.

The following example shows how to apply bold, italic, and underline formatting to selected text.


<!--Create a RichTextBox and three buttons.-->
<StackPanel>
    <RichTextBox x:Name="MyRTB" Width="600" Height="400" />
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <Button Content="Bold" Height="30" Margin="2" Width="50" Click="BtnBold_Click" />
        <Button Content="Italic" Height="30" Margin="2" Width="50" Click="BtnItalic_Click" />
        <Button Content="Underline" Height="30" Margin="2" Width="65" Click="BtnUnderline_Click" />
    </StackPanel>
</StackPanel>


No code example is currently available or this language may not be supported.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2017 Microsoft