Back to Devexpress

Interval.Length Property

blazor-devexpress-dot-blazor-dot-richedit-dot-interval-86a64911.md

latest2.5 KB
Original Source

Interval.Length Property

Returns the number of character positions in the interval.

Namespace : DevExpress.Blazor.RichEdit

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

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

csharp
public int Length { get; }

Property Value

TypeDescription
Int32

The interval length.

|

Remarks

The following example shows how you can access the selected paragraph:

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 {
        @* ... *@
            Document documentAPI = richEdit.DocumentAPI;
            Paragraph selectedParagraph;
            // Checks whether the main sub-document is active
            if (selection.ActiveSubDocument.Type == SubDocumentType.Main) {
                // Obtains all paragraphs in the main sub-document
                IReadOnlyList<Paragraph> paragraphs = await documentAPI.Paragraphs.GetAllAsync();
                // Gets the caret position
                int caretPosition = selection.CaretPosition;
                for (int i = 0; i < paragraphs.Count; i++) {
                    // Gets the interval that contains the current paragraph
                    Interval interval = paragraphs[i].Interval;
                    // Checks whether the caret is within the current paragraph
                    if (interval.Start <= caretPosition & caretPosition <= interval.Start + interval.Length - 1) {
                        selectedParagraph = paragraphs[i];
                        break;
                    }
                }
            }
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

See Also

Interval Class

Interval Members

DevExpress.Blazor.RichEdit Namespace