Xamarin: UIAlertView MessageBox

In Winforms development the MessageBox is a simple way of alerting the user of an action.

System.Windows.Forms.MessageBox.Show("This should be an error message","Error",MessageBoxButtons.OKCancel, MessageBoxIcon.Error);

Which produces:

MessageBox

To achieve similar functionality in iOS we utalise the UIAlertView.

UIAlertView alert = new UIAlertView ();
alert.Title = "Error";
alert.AddButton ("OK");
alert.AddButton ("Cancel");
alert.Message = "This should be an error message";
//alert.AlertViewStyle = UIAlertViewStyle.SecureTextInput;
alert.Show ();

Which produces:

UIAlertView

 

 

 

 

Also note the AlertViewStyle allows the view to take text input or act as a login screen.