Messagebox error

Asked

Viewed 206 times

3

I tried to implement the code below in a Windows Phone 8.1 project, the same had already been implemented in Windows Forms successfully.

What should I change to be valid for Windowsphone 8.1?

private void reset_Click(object sender, RoutedEventArgs e)
{
    const string message = "Voce deseja voltar o jogo ao seu estado normal ?";
    const string caption = "Reset";
    var result = MessageBox.Show(message, caption,
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question);

    if (result == DialogResult.No)
    {

    }
    else { this.Close(); /*re-estabeleçe valores*/ }

    }

Displays the following error:

The name 'Messagebox' does not exist in the Current context

2 answers

2


In the new Windows Phone Apis 8.1 you need to use await MessageDialog().ShowAsync() from Windows.UI.Popups. In your case, it would look like this:

var mensagem = new MessageDialog("Sua mensagem");
await mensagem.ShowAsync();

2

Windows Phone is not like Windows Forms. Your code should be something close to that:

private async void reset_Click(object sender, RoutedEventArgs e)
{
    const string message = "Voce deseja voltar o jogo ao seu estado normal ?";
    const string caption = "Reset";

    MessageBoxResult result = MessageBox.Show(message, caption, MessageBoxButton.OKCancel);

    if (result == MessageBoxResult.Cancel)
    {

    }
    else { this.Close(); /*re-estabeleçe valores*/ }

}

All this with:

using System.Windows;

in the file header.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.