Tags

, , ,

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());

Advertisements