Storyboard.BeginAsync()

public static Task BeginAsync(this Storyboard storyboard) {
    System.Threading.Tasks.TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
    if (storyboard == null)
        tcs.SetException(new ArgumentNullException());
    else {
        EventHandler<object> onComplete = null;
        onComplete = (s, e) => {
            storyboard.Completed -= onComplete;
            tcs.SetResult(true);
        };
        storyboard.Completed += onComplete;
        storyboard.Begin();
    }
    return tcs.Task;
}
Example:
await StoryBoard1.BeginAsync();

Description

Begin an XAML Storyboard using the async/await pattern instead of using the completed event.

Details

Double click on the code to select all.

 

;