Created
February 12, 2014 16:53
-
-
Save luiseduardohd/8959582 to your computer and use it in GitHub Desktop.
simple MessageBox para Xamarin ios
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
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