Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 431
sprrw Avatar asked Apr 07 '14 10:04

sprrw


2 Answers

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();
like image 157
ZombieSheep Avatar answered Oct 19 '22 11:10

ZombieSheep


Just wanted to add to ZombieSheep's answer: also, customization is quite simple

        var dialog = new MessageDialog("Are you sure?");
        dialog.Title = "Really?";
        dialog.Commands.Add(new UICommand { Label = "Ok", Id = 0 });
        dialog.Commands.Add(new UICommand { Label = "Cancel", Id = 1 });
        var res = await dialog.ShowAsync();

        if ((int)res.Id == 0)
        { *** }
like image 48
Vitalii Vasylenko Avatar answered Oct 19 '22 10:10

Vitalii Vasylenko