[FIXED] Refresh all navigation stacks to beginning when going to a different shell — Xamarin forms


I have a couple nav stacks in my xamarin form app like this. The searchPage and aboutPage are both visible/navigable as tabs on the bottom of the screen.


I am specifically interested in the case where someone has navigated to search results page (//searchPage/searchResultPage) and then uses the bottom tab to go to the aboutPage. Now that they are in the about page, if they click on the search page tab on the bottom, default behavior is that they’re brought back to the search result page since they never closed out of it. I’d like for this search result page to be closed out automatically so when they click the search page they are indeed brought there (beginning of nav stack) instead of to the search result page (end of nav stack).

Edit to add appshell/navigation script–


        <ShellContent Title="Search" Icon="icon_search.png" Route="SearchPage" ContentTemplate="{DataTemplate local:SearchPage}"/>
        <ShellContent Title="About" Icon="icon_about.png" Route="AboutPage" ContentTemplate="{DataTemplate local:AboutPage}"/>

Navigation on Search page:

async void LoadSearch(int passedNum)
            await Navigation.PushAsync(new ResultPage(passedNum));


You can Generate OnDisappearing override in searchResultPage.xaml.cs. Once leaving searchResultPage, it will call OnDisappearing automatically.
In OnDisappearing,the method PopAsync of Navigation pop searchResultPage from the navigation stack. So far, what you need is reached.

protected override void OnDisappearing()

Answered By – Jianwei Sun

Answer Checked By – Pedro (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published