MessageBox class problem (solved) in Windows Phone 8.1

In Windows Phone 8 we have to code MessageBox.Show("Some Messsage here"); but many people had issue with using MessageBox class while catching excaption in async methods, for example MessageBox.Show(ex.Message);. This was really painful.

MeeeMicrosoft has defined a solution for this with MessageDialog class

This is the way to invoke message dialog in WP8.1

MessageDialog messageDialog = new MessageDialog(ex.Message);
await messageDialog.ShowAsync();

That’s two lines of code where you had one before, plus you can’t await in the body of a catch clause. If those things are issues for you then one solution is a handy helper class.

public class MessageDialogHelper
public static async void Show(string content, string title)
MessageDialog messageDialog = new MessageDialog(content, title);
await messageDialog.ShowAsync();

Then call this class by
MessageDialogHelper.Show(ex.Message, ex.GetType().ToString());

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s