Skip to main content
All docs
V24.1

ValidationArgs.UseCancellationToken Property

Gets or sets whether changes made within a row can be canceled.

Namespace: DevExpress.Mvvm.Xpf

Assembly: DevExpress.Mvvm.v24.1.dll

NuGet Packages: DevExpress.Mvvm, DevExpress.Win.Navigation

Declaration

public bool UseCancellationToken { get; set; }

Property Value

Type Description
Boolean

true if changes made within a row can be canceled; otherwise, false.

Remarks

If you want to update a row asynchronously, create a command and bind it to the ValidateRowCommand or ValidateNodeCommand property.

Use the ResultAsync property to specify a task that asynchronously posts changes to an underlying data source (database).

You can also validate data and specify an error description. If the data are invalid, the task should return the ValidationErrorInfo object; otherwise, return null.

To allow a user to cancel changes, set the UseCancellationToken property to true and use the CancellationToken in a cancel function.

[Command]
public void UpdateIssue(RowValidationArgs args) {
    args.UseCancellationToken = true;
    args.ResultAsync = UpdateIssueAsync(args.Item as IssueData, args.CancellationToken);
}
static async Task<ValidationErrorInfo> UpdateIssueAsync(IssueData issue, CancellationToken token) {
    if(!IssuesService.ServerIsConnected)
        return new ValidationErrorInfo("Server is disconnected.", ValidationErrorType.Critical);
    await IssuesService.UpdateRowAsync(issue, token);
    return null;
} 

public async static System.Threading.Tasks.Task UpdateRowAsync(IssueData row, CancellationToken token) {
    if(row == null)
        return;
    IssueData data = null;
    for(int i = 0; i < AllIssues.Value.Length; i++) {
        if(token.IsCancellationRequested)
            return;
        if(AllIssues.Value[i].Id == row.Id)
            data = AllIssues.Value[i];
    }
    if(data == null)
        return;
    data.Priority = row.Priority;
    data.Subject = row.Subject;
    data.UserId = row.UserId;
    data.Votes = row.Votes;
    data.Created = row.Created;
    await System.Threading.Tasks.Task.Delay(500).ConfigureAwait(false);
}
See Also