Skip to main content

Document.BeginUpdate(Boolean) Method

Locks the Rich Text Editor to prevent its visual updates until the EndUpdate() method is called.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public void BeginUpdate(
    bool lockEditing = true
)

Optional Parameters

Name Type Default Description
lockEditing Boolean True

true to lock the entire component; false to lock the UI (ribbon) only.

Remarks

Enclose your code in the BeginUpdate - EndUpdate() method calls to suppress the RichEdit’s visual updates and improve its performance when you make multiple changes to a document.

Each call to BeginUpdate should be paired with the EndUpdate() call. The BeginUpdate method locks the component to prevent it from re-rendering after each modification. The EndUpdate() method unlocks the control to allow all the changes to be applied.

The following code snippet locks the Rich Text Editor until every paragraph in the main sub-document is updated.

<DxRichEdit @ref="richEdit" />
@code {
    DxRichEdit richEdit;
    protected override Task OnAfterRenderAsync(bool firstRender) {
        if (firstRender)
            InitializeDocument();
        return base.OnAfterRenderAsync(firstRender);
    }

    async void InitializeDocument() {
    /* 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 {
            richEdit.DocumentAPI.BeginUpdate();
            IReadOnlyList<Paragraph> paragraphs = await richEdit.DocumentAPI.Paragraphs.GetAllAsync();
            foreach (Paragraph p in paragraphs)
                await p.ChangePropertiesAsync(properties => {/*...*/});
            richEdit.DocumentAPI.EndUpdate();
            }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}
See Also