Skip to main content

CalculateDocumentVariableEventArgs.Arguments Property

Returns DOCVARIABLE field arguments.

Namespace: DevExpress.Blazor.RichEdit

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

NuGet Package: DevExpress.Blazor.RichEdit

Declaration

public string[] Arguments { get; }

Property Value

Type Description
String[]

An array of arguments.

Remarks

The DOCVARIABLE field code has the following structure that can include optional arguments:

{ DOCVARIABLE "variable name" ["argument1"] ["argument2"] ... }.

When the field is updated, the CalculateDocumentVariable event fires. Use the Arguments property to access an array of field arguments.

<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 {
            var position = richEdit.Selection.CaretPosition;
            await richEdit.DocumentAPI.Fields.CreateAsync(position, "DOCVARIABLE docvarName arg1 arg2 arg3");
        }
        catch (OperationCanceledException e) {
            Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
        }
    }

    async Task OnCalculateDocumentVariable(CalculateDocumentVariableEventArgs e) {
        switch (e.VariableName) {
            case "docvarName":
                var argument1 = e.Arguments[0];
                var argument2 = e.Arguments[1];
                var argument3 = e.Arguments[2];
                // Your code
                // e.Value = ... ;
                break;
            default:
                break;
        }
    }
}
See Also