Skip to content

Instantly share code, notes, and snippets.

@prashantvc
Last active December 24, 2015 07:19
Show Gist options
  • Save prashantvc/6762841 to your computer and use it in GitHub Desktop.
Save prashantvc/6762841 to your computer and use it in GitHub Desktop.
Task<int> ShowModalAletViewAsync (string title, string message, params string[] buttons)
{
var alertView = new UIAlertView (title, message, null, null, buttons);
alertView.Show ();
var tsc = new TaskCompletionSource<int> ();
alertView.Clicked += (sender, buttonArgs) => {
Console.WriteLine ("User clicked on {0}", buttonArgs.ButtonIndex);
tsc.TrySetResult(buttonArgs.ButtonIndex);
};
return tsc.Task;
}
//Usage
async Task PromptUser() {
var result = await ShowModalAletViewAsync ("Alert", "Do you want to continue?", "Yes", "No");
//process the result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment