Back to Devexpress

DxRichEdit.Selection Property

blazor-devexpress-dot-blazor-dot-richedit-dot-dxrichedit-e00939b8.md

latest2.0 KB
Original Source

DxRichEdit.Selection Property

Provides access to the Rich Text Editor’s selection.

Namespace : DevExpress.Blazor.RichEdit

Assembly : DevExpress.Blazor.RichEdit.v25.2.dll

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

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

Property Value

TypeDescription
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.

razor
<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

DxRichEdit Class

DxRichEdit Members

DevExpress.Blazor.RichEdit Namespace