Skip to main content

Bookmarks.CreateAsync(Interval, String, CancellationToken) Method

Creates a bookmark.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public ValueTask<Bookmark> CreateAsync(
    Interval interval,
    string name,
    CancellationToken cancellationToken = default(CancellationToken)
)

Parameters

Name Type Description
interval Interval

The sub-document’s text span interval in which to create the bookmark.

name String

The bookmark name.

Optional Parameters

Name Type Default Description
cancellationToken CancellationToken null

An object that propagates a cancellation notification.

Returns

Type Description
ValueTask<Bookmark>

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

Remarks

<DxRichEdit @ref="@richEdit" />

@code {
    DxRichEdit richEdit { get; set; }
    @* ... *@
    /* 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 {
        @* ... *@
            // Create a bookmark
            var bookmarkTextSpan = await richEdit.DocumentAPI.AddTextAsync("Chapter 1");
            var bookmarkChapter1 = await richEdit.DocumentAPI.Bookmarks.CreateAsync(bookmarkTextSpan.Interval, "chapter1Bookmark");
            @* ... *@
            // Create a hyperlink to the bookmark
            var hlChapter1Span = await richEdit.DocumentAPI.AddTextAsync("To learn more, see the Chapter 1");
            await richEdit.DocumentAPI.Hyperlinks.CreateAsync(hlChapter1Span.Interval, "", bookmarkChapter1.Name, "Go to Chapter 1");
            @* ... *@
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
}
See Also