Skip to main content

Bookmark Class

A bookmark in a document.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit


public class Bookmark :


A bookmark is an anchor in a document. Users can navigate to this anchor when they click a corresponding hyperlink.

Create a Bookmark

Call a Bookmarks.CreateAsync method to add a bookmark to a sub-document.

<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");
            @* ... *@
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");

Call a Hyperlinks.CreateAsync method to create a hyperlink that navigates to the bookmark.

// 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");

Find a Bookmark

Use the following methods to find a bookmark:

  • GetAsync(String, CancellationToken) - finds a bookmark by name

    // Find a bookmark by its name and get the bookmark's interval
    var bookmark = await richEdit.DocumentAPI.Bookmarks.GetAsync("chapter1Bookmark");
    if (bookmark != null) {
        var bookmarkInterval = bookmark.Interval;
  • GetAsync(Int32, CancellationToken) - finds a bookmark by index in the collection

    var firstBookmark = await richEdit.DocumentAPI.Bookmarks.GetAsync(0);
  • GetAllAsync(CancellationToken) - gets the collection of the bookmarks

    var bookmarks = await richEdit.DocumentAPI.Bookmarks.GetAllAsync();

Remove a Bookmark

Use the following methods to remove a bookmark:

  • RemoveAsync(Bookmark, CancellationToken) - removes the specified bookmark.

    var firstBookmark = await richEdit.DocumentAPI.Bookmarks.GetAsync(0);
    // Remove the first bookmark
    await richEdit.DocumentAPI.Bookmarks.RemoveAsync(firstBookmark);
  • RemoveAsync(Int32, CancellationToken) - removes a bookmark with the specified index.

    var bookmarks = await richEdit.DocumentAPI.Bookmarks.GetAllAsync();
    // Remove all bookmarks from the document
    while (bookmarks.Count > 0) {
        await richEdit.DocumentAPI.Bookmarks.RemoveAsync(0);
        bookmarks = await richEdit.DocumentAPI.Bookmarks.GetAllAsync();
  • RemoveAsync(String, CancellationToken) - removes a bookmark with the specified name.

    // Remove a bookmark by a name
    await richEdit.DocumentAPI.Bookmarks.RemoveAsync("chapter1Bookmark");

The Bookmark Dialog

The Rich Text Editor invokes this dialog when a user selects the InsertBookmark ribbon command or Bookmark context menu command. The Bookmark dialog allows users to create and delete bookmarks and navigate through them.

Bookmark Dialog


See Also