I'm using a TwoWay
databinding for a collection of objects, but when the field is edited, it needs to update to the backend model, which in turn need to call an async library code, but the data binding are bound to properties not methods, so my questions are:
1. is there a way to call async methods in
2. or is there a way to make databinding bind on methods rather than property, so that it can call the methods just like event handlers.Set
method of the property to do some async work
///
public class Model
{
public int Field
{
get { return field; }
set { field = value; await UpdateValue(field); } // won't compile
}
}
EDIT: I understand there is no support of async properties, also this question isn't really how to do async properties in a language as most of the answers focused. This question focus on how to implement this specific design problem, and I can imagine this would rise a lot when using databinding.
Suppose a data item is bind to a network service or database, then in the update path, one will need to do await socket.SendAsync(value)
or await db.SaveChanges(value)
. What is the proper way to solve this situation?