Exit Button Message - Xamarin Forms

Asked

Viewed 375 times

-1

I need a message on the Exit Button (I will use the Navigation.PopAsync()) next to what I did but that works (this one doesn’t work):

//Botão Sair
void BtnSair_Clicked(object sender, EventArgs e)
{
   var result = DisplayAlert("Alerta", "Deseja realmente sair?", "Sim", "Não");
   if (result) {Navigation.PopAsync();}  
}

1 answer

0


As for some it may be useful I managed to solve as follows:

private async Task BtnSair_Clicked(object sender, EventArgs e)
{
  var result = await DisplayAlert("Alerta", "Deseja realmente sair?", "Sim", "Não");

  if (result)
  {
    await Navigation.PopAsync();
  }
}

I noticed that Displayalert returns Task and the variable expected only bool, then in the call of the button I used private async Task and then await where you will have to wait for return.

Browser other questions tagged

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