MessageBox error

3

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

What should I change to be valid for Windows Phone 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

    
asked by anonymous 18.07.2014 / 04:57

2 answers

2

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

var mensagem = new MessageDialog("Sua mensagem");
await mensagem.ShowAsync();
    
04.09.2014 / 16:02
2

Windows Phone is not the same as Windows Forms. Your code should look something like this:

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 header of the file.

    
11.08.2014 / 20:00