Display a Direct Message on the Mainpage page

Asked

Viewed 51 times

3

How to display a direct message from Mainpage, I am using Messagedialog as 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 on this line:

         await saida.ShowAsync();

1 answer

1

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

In your case I recommend that you use the event loaded to run its features:

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();

       }

Further information on the await operator: MSDN|await (Reference of C#)

Browser other questions tagged

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