Class
TextSelection

Manages the current text range selected in a TextDocument, enabling querying, geometry extraction, and modification of the highlighted content.

Definition

Namespace:Telerik.Windows.Documents.Fixed.Selection

Assembly:Telerik.Windows.Documents.Fixed.dll

Syntax:

cs-api-definition
public class TextSelection

Inheritance: objectTextSelection

Properties

EndPosition

Gets the focus (later) text position of the current selection, or null when no selection exists.

Declaration

cs-api-definition
public TextPosition EndPosition { get; }

Property Value

TextPosition

The end position.

IsEmpty

Gets a value indicating whether no text is currently selected (start and end are identical or both null).

Declaration

cs-api-definition
public bool IsEmpty { get; }

Property Value

bool

true if the start and end positions are the same; otherwise, false.

StartPosition

Gets the anchor (earlier) text position of the current selection, or null when no selection exists.

Declaration

cs-api-definition
public TextPosition StartPosition { get; }

Property Value

TextPosition

The start position.

Methods

Clear()

Clears any current selection, leaving no selected text.

Declaration

cs-api-definition
public void Clear()

GetSelectedText()

Returns the text within the current selection range using document line separators, or an empty string if none is selected.

Declaration

cs-api-definition
public string GetSelectedText()

Returns

string

A string containing the text content within the current selection, or an empty string if no text is selected.

GetSelectedTextAsync()

Asynchronously retrieves the currently selected text; returns an empty string if another retrieval is already running.

Declaration

cs-api-definition
public Task<string> GetSelectedTextAsync()

Returns

Task<string>

A task that represents the asynchronous operation. The task result contains the text content within the current selection.

GetSelectionGeometry(RadFixedPage)

Builds a path geometry outlining the selected text fragments that lie on the specified page for highlighting or custom adorners.

Declaration

cs-api-definition
public PathGeometry GetSelectionGeometry(RadFixedPage page)

Parameters

page

RadFixedPage

The page for which to retrieve the selection geometry.

Returns

PathGeometry

A PathGeometry object representing the visual bounds of the text selection on the specified page.

Remarks

The geometry can be used for highlighting or other visual representations of the selected text.

SelectAll()

Selects the entire document content.

Declaration

cs-api-definition
public void SelectAll()

SetSelection(TextPosition, TextPosition)

Defines the selection range using the supplied start and end positions (both must belong to this document).

Declaration

cs-api-definition
public void SetSelection(TextPosition startPosition, TextPosition endPosition)

Parameters

startPosition

TextPosition

The start position.

endPosition

TextPosition

The end position.

SetSelectionEnd(TextPosition)

Sets or moves the end anchor of the selection while preserving the current start (or using it when none exists).

Declaration

cs-api-definition
public void SetSelectionEnd(TextPosition endPosition)

Parameters

endPosition

TextPosition

The end position.

SetSelectionStart(TextPosition)

Sets or moves the start anchor of the selection while preserving the current end (or using it when none exists).

Declaration

cs-api-definition
public void SetSelectionStart(TextPosition startPosition)

Parameters

startPosition

TextPosition

The start position.

ToString()

Returns the currently selected text.

Declaration

cs-api-definition
public override string ToString()

Returns

string

A string that represents the current object.

Overrides object.ToString()

Events

SelectionChanged

Raised after the selection range has changed.

Declaration

cs-api-definition
public event EventHandler SelectionChanged

Event Value

EventHandler

SelectionChanging

Raised before the selection range changes so listeners can update related UI state.

Declaration

cs-api-definition
public event EventHandler SelectionChanging

Event Value

EventHandler