Skip to main content

Fields.CreateAsync(Int32, Int32) Method

Creates a field in an interval. The interval is specified with the startPosition and length parameters.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<Field> CreateAsync(
    int startPosition,
    int length
)

Parameters

Name Type Description
startPosition Int32

The interval’s start position.

length Int32

The interval’s length.

Returns

Type Description
ValueTask<Field>

A structure that stores an awaitable result of an asynchronous operation. The awaitable result is a field object.

Remarks

The startPosition and the length parameters specify an interval in a sub-document. Call the CreateAsync(Int32, Int32) method to wrap the specified interval in a new field.

The following example shows how you can create a TIME field at the beginning of the main sub-document:

<DxRichEdit @ref="@richEdit" />

@code {
    DxRichEdit richEdit;
    Document documentAPI;
    @* ... *@
    /* 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 {
            documentAPI = richEdit.DocumentAPI;
            @* ... *@
            // Creates an empty field
            Field timeField = await documentAPI.Fields.CreateAsync(0, 0);
            // Inserts text to the field
            await documentAPI.AddTextAsync(1, "TIME");
            // Updates the field
            await documentAPI.Fields.UpdateAsync(timeField);
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}

Update a field to calculate and display the field result. The UpdateAsync(Field, CancellationToken) method allows you to update a field. Call the UpdateAllAsync(Boolean, CancellationToken) method to update every field in a sub-document or in all sub-documents.

See Also