microsoft / XamlBehaviors

This is the official home for UWP XAML Behaviors on GitHub.
MIT License
700 stars 112 forks source link

Support for Async/Await in Actions #112

Open Duranom opened 8 years ago

Duranom commented 8 years ago

XamlBehaviors are really powerfull and more lately noticed that some designers are going faster with productivity with the more small components made into it. But we are running into some small behaviors/actions issue when it comes to actions that require async/await.

A common scenario that we have is that the we have a lot of small actions that help the designers just plug in the feature where needed and out later instead of in code, this really sped up a lot of implementations and requirements but we are having issues when the designers need to do few actions in a row. For example assume there are 3 actions required to be executed but the second one is a IO operation with Async execute only that you either need to await or .Wait/Result and the third action relies on it. Currently you now either perform a blocking UI action while you want fluent UI or do in code behind (and dozen of places).

I would like to propose an addition of an IAwaitableAsync with the method Task Execute(object sender, object parameter); SideNote: Maybe even introduce a base class like with Behavior, one named BehaviorAction and AwaitableBehaviorAction

There are few critical changes that would be required though, like the Interaction.ExecuteActions would have to do a blocking support or replaced by a new method named Interaction.ExecuteActionsAsync. All Behaviors of the package would have to use that method to support Async/Await. CallMethodAction should also ignore the check if a method returns nothing to match the perfect signature and in case it returns a Task it should await it.

il-frans commented 4 years ago

Bumping this as I came across this issue, or am I missing something? Using EventTriggerBehavior -> CallMethodAction does not support async methods as far as I could tell.