Skip to content

Instantly share code, notes, and snippets.

@dannycabrera
Last active June 14, 2018 14:10
Show Gist options
  • Save dannycabrera/b55d62d5986d23bba2bdb21980e18000 to your computer and use it in GitHub Desktop.
Save dannycabrera/b55d62d5986d23bba2bdb21980e18000 to your computer and use it in GitHub Desktop.
Xamarin.Android await AlertDialog.Builder
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