Skip to main content

DxRichEdit.Selection Property

Provides access to the Rich Text Editor’s selection.

Namespace: DevExpress.Blazor.RichEdit

Assembly: DevExpress.Blazor.RichEdit.v24.1.dll

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

[Parameter]
public Selection Selection { get; set; }

Property Value

Type Description
Selection

An object that contains information about the selection.

Remarks

To access the editor’s selection in code, bind the Selection property with @bind-Selection attribute.

<DxRichEdit @bind-Selection="@selection" @ref="@richEdit" />

@code {
    DxRichEdit richEdit;
    Selection selection;
    @* ... *@
    /* Surround the code that contains an asynchronous operation with a try-catch block to handle
    the OperationCanceledException. This exception is thrown when an asynchronous operation is canceled. */
        try {
        @* ... *@
            // Applies bold formatting to characters in the selected intervals.
            IReadOnlyList<Interval> intervals = selection.Intervals;
            foreach (Interval interval in intervals) {
                TextSpan boldTextSpan = await richEdit.DocumentAPI.GetTextSpanAsync(interval);
                await boldTextSpan.ChangePropertiesAsync(properties => {
                    properties.FontBold = true;
                });
            }
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}
See Also