Pop 2 modals to return to main page

I have a Modal Page that appears when a button is clickes, and another Modal appears on another click of this Modal.

In the Main Page:

var puntajePage = new CargarPuntaje(puntos);
await Navigation.PushModalAsync(puntajePage);

And in the CargarPuntaje Modal:

var listado = new ListadoGanadores();
await Navigation.PushModalAsync(listado);

Then I use this to make the Modals disappear:

public async void OnButtonClicked(object sender,EventArgs args)
{
    await Navigation.PopModalAsync();
    await Navigation.PopModalAsync();
    //await Navigation.PopToRootAsync(); not working...
}

But it's not working...

Answers

  • kevinsalotkevinsalot USUniversity ✭✭

    When I had a similar issue, it was that I wasn't doing all of my page navigation on the same thread. Now I make sure that all navigation occurs on the main thread. One way to do that is with Device.BeginInvokeOnMainThread().

  • ilanolkiesilanolkies ARMember ✭✭

    Where did you use that? In App.cs? @kevinsalot

  • kevinsalotkevinsalot USUniversity ✭✭

    I meant just wrap all calls that do navigation to ensure they happen on same thread. Something like:

    Device.BeginInvokeOnMainThread(async () =>
    {
      var puntajePage = new CargarPuntaje(puntos);
      await Navigation.PushModalAsync(puntajePage);
    });
    

    And:

    Device.BeginInvokeOnMainThread(async () =>
    {
      await Navigation.PopModalAsync();
    });
    
  • ilanolkiesilanolkies ARMember ✭✭

    Thanks! I'll try it @kevinsalot

Sign In or Register to comment.