top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

I need some assistance to Understanding Message Box in Windows Phone using C#?

+1 vote
375 views
I need some assistance to Understanding Message Box in Windows Phone using C#?
posted Feb 5, 2015 by Saravanan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

At first let’s see what different kind of buttons exist:

OK
OK, Cancel
Yes, No
Yes, No, Cancel
Retry, Cancel
Abort, Retry, Ignore

A message box is a dialog box that displays an alert or a message or also lets the user have some options to choose from.

A simple message box has an OK button

enter image description here

Simple MessageBox

A simple MessageBox shows a message and only has an OK button. Clicking on the OK button closes the MessageBox. The following line of code uses the Show method to display a message box with a simple message:

MessageBoxResult result = MessageBox.Show("Hello MessageBox");

The MessageBox generated by the line of code above is a modal dialog with an OK button

enter image description here

MessageBox with Title

A MessageBox can have a title. The first parameter of the Show method is a message string and second parameter is title string of the dialog. The following code snippet creates a MessageBox with a message and a title.

MessageBoxResult result = MessageBox.Show("Hello MessageBox", "Confirmation");

enter image description here

MessageBox with Title, Yes and No Buttons

The following code snippet creates a MessageBox with a message, a title, and two Yes and No buttons.

    if (MessageBox.Show("Do you want to close this window?",  "Confirmation", MessageBoxButton.YesNo) == 
        MessageBoxResult.Yes)
        {
             // Close the window
         }
  else
       {
           // Do not close the window
       } 

enter image description here

MessageBox with Title, Yes, No and Cancel Buttons

The following code snippet creates a MessageBox with a message, a title, and two Yes, No, and Cancel buttons.

MessageBoxResult result = MessageBox.Show("Do you want to close this window?", "Confirmation", 
 MessageBoxButton.YesNoCancel);
if (result == MessageBoxResult.Yes)
{
    // Yes code here
}
else if (result == MessageBoxResult.No)
{
    // No code here
}
else
{
    // Cancel code here
} 

enter image description here

MessageBox with Title, Icon, Yes and No Buttons

A MessageBox also allows you to place an icon that represents the message and comes with some built-in icons. The MessageBoxImage enumeration represents an icon. Here is a list of MessageBoxImage enumeration values that represent the relative icons.
None
Hand
Question
Exclamation
Asterisk
Stop
Error
Warning
Information
The following code snippet creates a MessageBox with a message, a title, and two Yes and No buttons and an icon.

string message = "Are you sure?";
string caption = "Confirmation";
MessageBoxButton buttons = MessageBoxButton.YesNo;
MessageBoxImage icon = MessageBoxImage.Question;
if (MessageBox.Show(message, caption, buttons, icon) == MessageBoxResult.OK)
{
    // OK code here
}
else
{
    // Cancel code here
} 

enter image description here

answer Feb 12, 2015 by Jdk
Similar Questions
+1 vote

The windows phone emulator wasn't able to ensure the virtual machine was running
Something happened while starting a virtual machine: Emulator WVGA 512MB. Could not initilize.
Not enough memory in the system to start virtual machine Emulator WVGA 512.MB XXXXXXX with ram size 512 megabytes

Any give me a appropriate solution to resolve this.

+1 vote

I am using Visual Studio 2013 for developing windows phone application how to test my application any one explain how can i achieve this... thanks in advance:)

+2 votes

I need XAP File for put my own application in my windows phone local store but i dont know where the XAP file placed in my application...........

...