Forum Xamarin.Forms

How to determine if Page was opened as PopAsync or PopModalAsync?

JassimRahmaJassimRahma USMember ✭✭✭✭

Hi,

How to determine if Page was opened as PushAsync or PushModalAsync?

I have a Page which sometimes I open as PushAsync and sometimes as PushModalAsync

so from the opened page, how can I know this page was opened using PushAsync or PushModalAsync

Thanks,
Jassim

Best Answer

Answers

  • mjdevelopermjdeveloper Member ✭✭✭
    edited October 2019

    hi
    You can check NavigationStack.

    var currentStack = yourparentPage.Navigation.NavigationStack;
    
    for(i=0; i <currentStack.count; i++)
    {
        if (currentStack[i].GetType() == typeofyourPage)
        {
              //is Opend
        }
    }
    
  • NMackayNMackay GBInsider, University admin

    @AlessandroCaliaro suggestion is the quickest way from experience.

  • YelinzhYelinzh Member, Xamarin Team Xamurai

    After navigation, get the navigationstack list and check if the list is empty, you will know which stack the page belongs to.

    List<Page> pagesLikeMe = Navigation.NavigationStack.Where(p => p is MainPage).ToList();
    
    if (pagesLikeMe.Count == 0)
    {
        //modal stack
    }
    else
    { 
        //navigation stack
    }
    
Sign In or Register to comment.