Skip to main content

Interval.Length Property

Returns the number of character positions in the interval.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

[JsonPropertyName("length")]
public int Length { get; }

Property Value

Type Description
Int32

The interval length.

Remarks

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

<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