[英]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>
因此,通過側欄(外殼) - 我單擊“申請貸款”,這LoanApplication.xaml
我帶到LoanApplication.xaml
。 此時,導航中沒有添加任何堆棧。 在LoanApplication.xaml
,我使用綁定到按鈕的PushAsync
將我帶到名為AmountLoanable.xaml
的頁面。 這將被添加到堆棧中,並且操作欄上的后退按鈕現在可用。
完成AmountLoanable.xaml
上的AmountLoanable.xaml
,我使用PopToRootAsync
刪除除根頁面(即<Shell>
、 MainPage.xaml
)之外的導航堆棧。 但是,它帶我回到之前選擇的“申請貸款”,我想要發生的是加載一個全新的<Shell>
MainPage.xaml
頁面。 這樣,第一頁(貸款歷史)將被選中,而不是通過<Shell>
訪問的最后一頁
嘗試將您的Application.Current.MainPage
重置為您的默認 Shell,例如: Application.Current.MainPage = new AppShell();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.