Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Interval.Length Property

Returns the number of character positions in the interval.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

#Declaration

C#
public int Length { get; }

#Property Value

Type Description
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