如何导航到具有 Shell 弹出菜单的新页面?

Ant*_*tin 1 xamarin xamarin.forms xamarin.forms.shell

我需要导航到一个页面,该页面将有 shell 弹出菜单,但我不需要它作为菜单中的项目出现。

我尝试过路由页面

Routing.RegisterRoute("cart", typeof(Cart));
Run Code Online (Sandbox Code Playgroud)

然后使用

Shell.Current.GoToAsync("///cart");
Run Code Online (Sandbox Code Playgroud)

但它抛出一个错误,告诉我堆栈中唯一的页面。微软文档没有帮助。

全局路由当前不能是堆栈上的唯一页面,因此不支持到全局路由的绝对路由。现在,只需导航至:cart/

当我尝试时

Shell.Current.Navigation.PushAsync(new NavigationPage(new Cart()));
Run Code Online (Sandbox Code Playgroud)

它有效,但顶部栏是默认颜色并且菜单按钮不存在。另外,我尝试将购物车作为新页面推送,没有new NavigationPage(),顶栏没有变化,但菜单按钮充当后退按钮,即使我设置了行为

<Shell.BackButtonBehavior>
        <BackButtonBehavior IconOverride="back.png"/>
</Shell.BackButtonBehavior>
Run Code Online (Sandbox Code Playgroud)

Rya*_*tal 7

使用Shell.Current.GoToAsync只会将另一个页面推送到导航堆栈中,

如果你想使用 shell 导航到另一个导航页面,你可以创建另一个 Shell 文件,例如:AppShell.xaml(shell 的默认设置)只需更改您的MainPage

Application.Current.MainPage = new NewAppShell();
Run Code Online (Sandbox Code Playgroud)