Back to Devexpress

ValidationArgs.ResultAsync Property

corelibraries-devexpress-dot-mvvm-dot-xpf-dot-validationargs-0407e9ba.md

latest5.7 KB
Original Source

ValidationArgs.ResultAsync Property

Gets or sets a task that asynchronously posts changes to an underlying data source (database).

Namespace : DevExpress.Mvvm.Xpf

Assembly : DevExpress.Mvvm.v25.2.dll

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

Declaration

csharp
public Task<ValidationErrorInfo> ResultAsync { get; set; }
vb
Public Property ResultAsync As Task(Of ValidationErrorInfo)

Property Value

TypeDescription
Task<ValidationErrorInfo>

A task that asynchronously posts changes to an underlying data source (database).

|

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.

csharp
[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);
}

Limitation

Async validation for cells is not supported. The GridControl throws an exception if you specify the ResultAsync property in the command bound to the GridViewBase.ValidateCellCommand property.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ResultAsync property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-bind-to-infiniteasyncsource/CS/InfiniteAsyncSourceMVVMSample/IssueServiceViewModel.cs#L82

csharp
if(args.IsNewItem) {
    args.ResultAsync = AddNewIssueAsync((IssueData)args.Item);
} else {

how-to-bind-to-grpc/CS/InfiniteAsyncSource.GRPC/IssueServiceViewModel.cs#L98

csharp
public void UpdateIssue(RowValidationArgs args) {
    args.ResultAsync = UpdateIssueAsync((Issue)args.Item);
}

wpf-data-grid-extend-crud-operations/CS/AsyncCRUDOperations/MainViewModel.cs#L19

csharp
var item = (User)args.Item;
args.ResultAsync = Task.Run(async () => {
    await Task.Delay(3000);

wpf-data-grid-extend-crud-operations/VB/AsyncCRUDOperations/MainViewModel.vb#L27

vb
Dim item = CType(args.Item, User)
args.ResultAsync = Task.Run(Async Function()
    Await Task.Delay(3000)

See Also

ValidationArgs Class

ValidationArgs Members

DevExpress.Mvvm.Xpf Namespace