My issue might be similar to this one: https://www.telerik.com/forums/async-await-inside-row-validating-event
I'm wanting to validate by cell, as opposed to by row. Similar to the above, validation works fine when no async calls are made, but progresses as if the validation wasn't there as soon as there is an async call of any sort.
In my case, I'm wanting to use the Cell Validating event not strictly for validation, but rather to provide a prompt to the user and have them answer yes or no before progressing. But I need to be able to run the event with async/await as I am calling async methods.
I can slightly get around this by calling the async methods with in a synchronous-like way, by calling the Wait() method on a Task, for instance. But it is much less convenient to do so.
Is the Telerik UI for WPF library still unable to cope with async validating events like described in the above thread or is there a way to make this situation work?
// This would be preferred
public
async
void
CellValidating(GridViewCellValidatingEventArgs e)
{
var result = await
this
.Dispatcher.InvokeAsync(() => MessageBox.Show(
"Test"
,
"Test"
, MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes));
if
(result == MessageBoxResult.No)
{
e.IsValid =
false
;
e.ErrorMessage =
"This is an error"
;
}
}
// This is what I have to do instead
public
void
CellValidating(GridViewCellValidatingEventArgs e)
{
var op =
this
.Dispatcher.InvokeAsync(() => MessageBox.Show(
"Test"
,
"Test"
, MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes));
_ = op.Wait();
var result = op.Result;
if
(result == MessageBoxResult.No)
{
e.IsValid =
false
;
e.ErrorMessage =
"This is an error"
;
}
}