Skip to content

Instantly share code, notes, and snippets.

@luiseduardohd
Created February 12, 2014 16:53
Show Gist options
  • Save luiseduardohd/8959582 to your computer and use it in GitHub Desktop.
Save luiseduardohd/8959582 to your computer and use it in GitHub Desktop.
simple MessageBox para Xamarin ios
public static class MessageBox
{
public static void Show(string title, string message, MessageBoxButton buttons, Action positiveCallback, Action negativeCallback)
{
UIAlertView alert = BuildAlert(title, message, buttons);
alert.Clicked += (sender, buttonArgs) =>
{
if (buttonArgs.ButtonIndex == 0)
{
positiveCallback();
}
else
{
negativeCallback();
}
};
NSThread.MainThread.InvokeOnMainThread (alert.Show);
}
public static void Show(string title, string message)
{
UIAlertView alert = BuildAlert(title, message, MessageBoxButton.OK);
NSThread.MainThread.InvokeOnMainThread(alert.Show);
}
public static void Show(string title, string message, MessageBoxButton buttons, Action positiveCallback)
{
UIAlertView alert = BuildAlert(title, message, buttons);
alert.Clicked += (sender, buttonArgs) =>
{
if (buttonArgs.ButtonIndex == 0)
{
positiveCallback();
}
};
NSThread.MainThread.InvokeOnMainThread(alert.Show);
}
static UIAlertView BuildAlert(string title, string message, MessageBoxButton buttons)
{
switch(buttons)
{
case MessageBoxButton.OK :
return new UIAlertView(title, message, null, "Ok", null);
case MessageBoxButton.OKCancel :
return new UIAlertView(title, message, null, "Ok", "Cancel");
case MessageBoxButton.YesNo :
return new UIAlertView(title, message, null, "Yes", "No");
default:
return new UIAlertView(title, message, null, "Ok", null);
}
//throw new NotImplementedException(buttons.ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment