Popup.ShowAsync()
Show an XAMP Popup using the async/await pattern instead of using the completed event.
Source
public static Task ShowAsync(this Popup popup) {
TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
EventHandler<object> onClosed = null;
onClosed = (s, e) => {
popup.Closed -= onClosed;
tcs.SetResult(true);
};
popup.Closed += onClosed;
popup.IsOpen = true;
return tcs.Task;
}
Example
private async void Button_Click(object sender, RoutedEventArgs e) {
await this.popupTest.ShowAsync();
(sender as Button).Content = "Closed at " + DateTime.Now.ToString("HH:mm:ss");
}
Author: Fons Sonnemans
Submitted on: 7 nov. 2013
Language: C#
Type: Windows.UI.Xaml.Controls.Primitives.Popup
Views: 6819