Displaying a Messagebox in Universal Apps

While I was working on a universal app I wanted to display a simple message dialog. So I started typing:

MessageBox.Show(“Foo”,“Bar”)

So I figured a namespace was missing in the code. Therefore I let Resharper fix it for me. After pressing alt-enter I saw that resharper couldn’t help me with it. So I figured something else must be wrong here. The correct solution was the following:


var dialog =
new
MessageDialog(“Are you sure you wanna do something?”, “Delete something”);

dialog.Commands.Add(new
UICommand(“Cancel”));

dialog.Commands.Add(new
UICommand(“Yes”, (command => ViewModel.DeleteSomethingCommand.Execute(null))));

 


await dialog.ShowAsync();

I create a dialog with a title and a message and I’ve added two commands to it. The cancel command does nothing in this case. The “Yes” command triggers a command in my viewmodel. You can also set the default command index but because my cancel command is the first command that was added to the collection this is the correct command in my case.

Leave a comment

Your email address will not be published.

*