Universal Apps MessageBox: "The name 'MessageBox' does not exist in the current context"

sprrw picture sprrw · Apr 7, 2014 · Viewed 81.3k times · Source

I want to use MessageBox for showing download errors in my WP8.1 app.

I added:

using System.Windows;

but when I type:

MessageBox.Show("");

I get error:

"The name 'MessageBox' does not exist in the current context"

In Object Browser I found that such class should exist and in "Project->Add reference... ->Assemblies->Framework" is shown that all assemblies are referenced.

Do I miss something? Or is there another way how to show something like messagebox?

Answer

ZombieSheep picture ZombieSheep · Apr 7, 2014

For Universal Apps, the new APIs require you to use await MessageDialog().ShowAsync() (in Windows.UI.Popups) to bring it into line with Win 8.1.

var dialog = new MessageDialog("Your message here");
await dialog.ShowAsync();