DxRichEdit.CalculateDocumentVariable Event

Fires when a DOCVARIABLE field is updated and allows you to specify the field result.

Namespace: DevExpress.Blazor.RichEdit

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

Declaration

[Parameter]
public EventCallback<CalculateDocumentVariableEventArgs> CalculateDocumentVariable { get; set; }

Event Data

The CalculateDocumentVariable event's data class is CalculateDocumentVariableEventArgs. The following properties provide information specific to this event:

Property Description
Arguments Returns DOCVARIABLE field arguments.
Value Specifies the result of the DOCVARIABLE field that fired the event.
VariableName Gets the name of the currently processed document variable.

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.

<DxRichEdit  @bind-Selection="@selection" @ref="@richEdit" 
    CalculateDocumentVariable="@(async x => await OnCalculateDocumentVariable(x))" />
@code {
    DxRichEdit richEdit { get; set; }
    Selection selection { 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 cancelled. */
        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 e) {
        try {
            switch (e.VariableName) {
                case "paragraphCount":
                    var paragraphs = await richEdit.DocumentAPI.Paragraphs.GetAllAsync();
                    e.Value = paragraphs.Count.ToString();
                    break;
                default:
                    break;
            }
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }
}

``` Docvariable field

See Also