Back to Devexpress

Fields.CreateAsync(Int32, Int32) Method

blazor-devexpress-dot-blazor-dot-richedit-dot-fields-dot-createasync-x28-system-dot-int32-system-dot-int32-x29.md

latest3.0 KB
Original Source

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.v25.2.dll

NuGet Package : DevExpress.Blazor.RichEdit

Declaration

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

Parameters

NameTypeDescription
startPositionInt32

The interval’s start position.

| | length | Int32 |

The interval’s length.

|

Returns

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

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

Fields Class

Fields Members

DevExpress.Blazor.RichEdit Namespace