PopToRootAsync 到选定的 Shell 弹出项目

PopToRootAsync to a selected Shell Flyout Item

我在下面使用此代码使用 <Shell> 创建一个带有集成边栏的操作栏,以便用户可以通过向右滑动轻松导航。作为 C# 的新手,我知道第一个 ShellContent 将是应用程序打开时 <Shell> 加载和预览的页面,即 ContentTemplate="{DataTemplate local:LoanHistory}"

我也明白,当您单击 FlyoutItems 时,您不会将堆栈添加到导航中,但 <Shell> 会在您每次单击时更改内容。下面的代码位于名为 MainPage.xaml

的文件中
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:local="clr-namespace:LoanApp2.Views"
             mc:Ignorable="d"
             x:Class="LoanApp2.MainPage" BackgroundColor="#62bef0" Title="Dylan">

    <FlyoutItem Title="MyTabApp" Shell.TabBarIsVisible="False" FlyoutDisplayOptions="AsMultipleItems">

        <ShellContent Title="Loan History" IsTabStop="False" ContentTemplate="{DataTemplate local:LoanHistory}"/>
        <ShellContent Title="Apply for Loan" IsTabStop="False" ContentTemplate="{DataTemplate local:LoanApplication}"/>
        <ShellContent Title="Logout" IsTabStop="False"  ContentTemplate="{DataTemplate local:LoanHistory}"/>
    </FlyoutItem>

</Shell>

因此,通过侧边栏 (shell) - 我单击“申请贷款”,然后转到 LoanApplication.xaml。此时,导航中还没有添加任何堆栈。在 LoanApplication.xaml 中,我使用绑定到按钮的 PushAsync 将我带到名为 AmountLoanable.xaml 的页面。这已添加到堆栈中,操作栏上的后退按钮现在可用。

完成 AmountLoanable.xaml 上的内容后,我使用 PopToRootAsync 删除导航堆栈,除了根页面(即 <Shell>MainPage.xaml).但是,它让我回到之前选择的 "Apply for Loan",我想要的是加载一个全新的 <Shell>MainPage.xaml 页面。这样,第一页(贷款历史)将被选中,而不是通过 <Shell>

访问的最后一页

尝试将您的 Application.Current.MainPage 重置为默认设置 Shell 例如:Application.Current.MainPage = new AppShell();