How to display message using Message box in Windows phone application

In this blog post I will explain you how to display message to user through a Message box in Windows phone application.

A message box is a very non-invasive way to tell the user that something needs his attention and maybe ask for a choice of action.

 

The Message box class that we shall be using is quite limited when it comes to user customization.

In Silverlight application there are two overload methods available as shown below.

 


 

First method

The first method allow the developer to display a simple message with an OK button – as basic as it can get and it is perfect for situations where you don’t need the user to make a decision.

 

An example is shown below

Type 1:


 

 

There is no title here and no additional buttons, so this might be a limitation in some situations.

 

Second method

The second method by allowing the developer to set the title and actually select, whether there is an OK or OKCancel button set needed.

Examples are given below

 

Type 2:

Ok button with a specific heading

 


 

Type 3:

Ok and cancel button with a specific heading. We track the response from the MessageBox via MessageBoxResult in result variable.


 

Note:

When you want to check the result, you will be prompted with an enumeration of possible values and in fact, it is bigger than you expect:


Only OK and Cancel will work if checked against. Other options will simply be ignored, since there is no Yes or No button available. Now, you might think – what about None? This also isn’t an option – when the user closes the MessageBox in a non-standard manner (e.g. by pressing the Back button), the result that is automatically passed as a response is MessageBoxResult.Cancel, even if no Cancel button is pressed.

 

I have a created a simple application to display the different types of Messagebox as explained above.

You can download the full source code of the project file from the link given below.

Download full project file Messagebox,zip

You can also refer to the following blog post where I have made an efficient use of the Messagebox class to add app review reminder in Windows phone application.

http://www.windowsapptutorials.com/windows-phone/general/adding-app-review-reminder-in-windows-phone-app-without-using-rate-my-app-toolkit/

 

 

Chetan Gulati

Currently am doing B TECH in IT from Delhi Technological University. App development is my passion. Believe in quality rather than quantity.

  • Manuel Antunes

    great stuff!

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding
Close