Last active
June 14, 2018 14:10
-
-
Save dannycabrera/b55d62d5986d23bba2bdb21980e18000 to your computer and use it in GitHub Desktop.
Xamarin.Android await AlertDialog.Builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
await AlertAsync(this, "My Title", "My Message", "Yes", "No"); | |
public Task<bool> AlertAsync(Context context, string title, string message, string positiveButton, string negativeButton) | |
{ | |
var tcs = new TaskCompletionSource<bool>(); | |
using (var db = new AlertDialog.Builder(context)) | |
{ | |
db.SetTitle(title); | |
db.SetMessage(message); | |
db.SetPositiveButton(positiveButton, (sender, args) => { tcs.TrySetResult(true); }); | |
db.SetNegativeButton(negativeButton, (sender, args) => { tcs.TrySetResult(false); }); | |
db.Show(); | |
} | |
return tcs.Task; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment