Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

CalculateDocumentVariableEventArgs Class

Provides data for the CalculateDocumentVariable event.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

#Declaration

C#
public class CalculateDocumentVariableEventArgs :
    EventArgs

#Remarks

Handle the CalculateDocumentVariable event to calculate a value of the DOCVARIABLE field. The VariableName event argument’s property identifies the processed field. Set the Value property to the field result value.

Razor
<DxRichEdit  @bind-Selection="@selection" @ref="@richEdit" 
    CalculateDocumentVariable="@(async x => await OnCalculateDocumentVariable(x))" />

@code {
    DxRichEdit richEdit { get; set; }
    Selection selection { get; set; }
    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 {
            await richEdit.DocumentAPI.Fields.CreateAsync(richEdit.Selection.CaretPosition, "DOCVARIABLE paragraphCount");
            await richEdit.DocumentAPI.AddTextAsync("Number of paragraphs: ");
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
    async Task OnCalculateDocumentVariable(CalculateDocumentVariableEventArgs eventArgs) {
        try {
            switch (eventArgs.VariableName) {
                case "paragraphCount":
                    var paragraphs = await richEdit.DocumentAPI.Paragraphs.GetAllAsync();
                    eventArgs.Value = paragraphs.Count.ToString();
                    break;
                default:
                    break;
            }
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

#Inheritance

Object
EventArgs
CalculateDocumentVariableEventArgs
See Also