简体   繁体   English

PopToRootAsync 到选定的 Shell 弹出项目

[英]PopToRootAsync to a selected Shell Flyout Item

I have this code below to create an action bar with an integrated side bar using <Shell> so the user can navigate easily by swiping right.我在下面使用此代码使用<Shell>创建一个带有集成侧边栏的操作栏,以便用户可以通过向右滑动轻松导航。 Being new to C#, I understand that the first ShellContent is gonna be the page to be loaded and previewed by the <Shell> when the app opens which is ContentTemplate="{DataTemplate local:LoanHistory}"作为 C# 的新手,我知道第一个 ShellContent 将是应用程序打开时由<Shell>加载和预览的页面,即ContentTemplate="{DataTemplate local:LoanHistory}"

I also understand when you click on the FlyoutItems you aren't gonna add stack to the navigation but the <Shell> is changing the contents each time you click on it.我也明白当您单击 FlyoutItems 时,您不会向导航添加堆栈,但是<Shell>每次单击它时都会更改内容。 This code below is in a file called MainPage.xaml以下代码位于名为 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>

So, via the side bar (shell) - I click on Apply for Loan which takes me to LoanApplication.xaml .因此,通过侧栏(外壳) - 我单击“申请贷款”,这LoanApplication.xaml我带到LoanApplication.xaml By this time, no stack is added to the navigation.此时,导航中没有添加任何堆栈。 In the LoanApplication.xaml , I'm using PushAsync binded to a button to take me to a page called AmountLoanable.xaml .LoanApplication.xaml ,我使用绑定到按钮的PushAsync将我带到名为AmountLoanable.xaml的页面。 This gets added to the stack and the back button on the action bar is now available.这将被添加到堆栈中,并且操作栏上的后退按钮现在可用。

After I am done with the stuff on AmountLoanable.xaml , I use PopToRootAsync to remove the navigation stack except for the root page (which is the <Shell> , MainPage.xaml ).完成AmountLoanable.xaml上的AmountLoanable.xaml ,我使用PopToRootAsync删除除根页面(即<Shell>MainPage.xaml )之外的导航堆栈。 However, it takes me back to the "Apply for Loan" which was selected prior, what I want to happen is for it to load a fresh new <Shell> , MainPage.xaml page.但是,它带我回到之前选择的“申请贷款”,我想要发生的是加载一个全新的<Shell> MainPage.xaml页面。 In that way, the first page (Loan History) will be the one selected instead of the last page accessed via <Shell>这样,第一页(贷款历史)将被选中,而不是通过<Shell>访问的最后一页

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM