当转到不同的shell -- Xamarin窗体时,刷新所有导航堆栈到开始位置

puruo6ea  于 2022-12-07  发布在  Shell
关注(0)|答案(1)|浏览(117)

我在我的Xamarin表单应用程序中有几个导航栈,就像这样。SearchPage和AboutPage都是屏幕底部的可见/可导航标签。

searchPage
    searchResultPage
aboutPage
    settingsPage

我特别感兴趣的是有人导航到搜索结果页面的情况(//searchPage/searchResultPage),然后使用底部的选项卡转到aboutPage。现在他们已经在About页面中,如果他们单击底部的搜索页面选项卡,默认的行为是,他们被带回到搜索结果页面,因为他们从来没有关闭了它。我希望这个搜索结果页面被自动关闭,所以当他们点击搜索页面时,他们确实被带到那里(导航栈的开始),而不是搜索结果页面(导航栈的结束)。
编辑以添加appshell/导航脚本--
应用程序 shell 程序:

<TabBar>
        <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}"/>
</TabBar>

搜索页面上的导航:

async void LoadSearch(int passedNum)
        {
            await Navigation.PushAsync(new ResultPage(passedNum));
        }
0kjbasz6

0kjbasz61#

你可以在searchResultPage.xaml.cs中生成OnDisappearing覆盖。一旦离开searchResultPage,它会自动调用OnDisappearing。在OnDisappearing中,Navigation的方法PopAsync从导航堆栈中弹出searchResultPage。至此,你所需要的已经达到。

protected override void OnDisappearing()
        {
            base.OnDisappearing();
            Navigation.PopAsync();
        }

相关问题