[英]How do I go to the Shell page and leave the menu button?
如果我從 Shell 菜單項導航到其他頁面,那么我可以選擇再次打開下拉菜單。 而如果我go從里面的代碼跳轉到頁面,那么左上角的菜單按鈕就沒有了。
await Shell.Current.GoToAsync("step");
如何從代碼打開頁面,打開頁面中的內容是 shell 菜單按鈕?
如果您導航到作為 Shell 視覺層次結構的一部分存在的頁面並注冊如下所示的路線。
<ShellContent
Title="Page1"
ContentTemplate="{DataTemplate local:Page1}"
Icon="tab_about.png"
Route="about" />
它可以使用如下參數進行導航。
await Shell.Current.GoToAsync("//about");
當您導航時,漢堡圖標仍然存在。
如果您導航到 Shell 視覺層次結構中不存在的頁面並使用Routing.RegisterRoute
注冊,它將覆蓋所有頁面並且不會顯示漢堡圖標。 但是您可以使用左上角的后退按鈕返回 Shell。
Routing.RegisterRoute("step", typeof(Page2));
編輯隊列總是滿的:所以這是我對 Wendy 的回答的擴展:
TLDR :
本質上,漢堡包導航僅在添加或注冊到 Shell 或其子BaseShellItem
之一的頁面上可見,因此是 Shell 視覺層次結構的一部分 -> 如果頁面是通過 AppShell.xaml 注冊的(也可以通過編程方式添加) 然后頁面被添加到BaseShellItem
並且是 Shell 視覺層次結構的一部分。
有幾種方法可以注冊導航頁面並確定頁面是否顯示漢堡包:
<ShellContent
Title="This is Page1"
ContentTemplate="{DataTemplate local:Page1}"
Icon="tab_about.png"
Route="Page1" />
您可以使用如下參數進行導航。
await Shell.Current.GoToAsync("//Page1");
當您導航時,漢堡包圖標仍會存在,因為頁面已添加到BaseShellItem
( BaseShellItem
-> ShellContent
)。
AppShell.xaml
中而是通過Routing
注冊頁面:Routing.RegisterRoute(nameof(page1), typeof(Page1));
並導航到頁面,它將覆蓋所有頁面並且漢堡包圖標不會顯示,因為它沒有添加到BaseShellItem
。 但是您可以使用左上角的后退按鈕將 go 返回到 Shell。
BaseShellItem
來注冊頁面(自 Xamarin.Forms 5 起),但不將其顯示在 Shell 的菜單中,並通過將其添加到FlyoutItem
中的 FlyoutItem 來使頁面具有漢堡包導航菜單AppShell.xaml
和使用FlyoutItemIsVisible="False"
:<FlyoutItem
Title="Stat Page"
FlyoutItemIsVisible="False"
IsEnabled="True">
<ShellContent
Title="Page1"
ContentTemplate="{DataTemplate local:Page1}"
Icon="tab_about.png"
Route="about" />
</FlyoutItem>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.