View a Direct Message on the MainPage page

3

How to display a message directly from MainPage, I'm using MessageDialog, as per the code below:

namespace App4
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            var saida = new MessageDialog("Exibir Mensagem");
            //Debug.WriteLine(saida);
            await saida.ShowAsync();

            this.NavigationCacheMode = NavigationCacheMode.Required;
        }

The error is in this line:

         await saida.ShowAsync();
    
asked by anonymous 27.09.2015 / 22:37

1 answer

1

The keyword await can only be used in methods that have keyword async . However, the contributors do not allow keyword async , only methods.

In your case I recommend that you use the loaded event to perform its functions:

namespace App4
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += MainPage_Loaded;

            this.NavigationCacheMode = NavigationCacheMode.Required;
        }

        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
       {
           var saida = new MessageDialog("Exibir Mensagem");
          //Debug.WriteLine(saida);
          await saida.ShowAsync();

       }

More information about the await operator: MSDN | await (C # Reference)

p>     
24.04.2016 / 17:00