我正在使用Xamarin Forms应用程序并将其转换为MAUI。
在Android中,我发现如果我导航到不同的页面,我会失去顶部导航栏中的弹出按钮(汉堡包按钮)。我还没有在iOS中尝试过,但我认为这是同样的行为。
以下是我导航到初始页面的方式:
private void LaunchInitialPage(Page page)
{
FlyoutPage FlyoutPage = new FlyoutPage
{
Detail = new NavigationPage(page)
{
BarBackgroundColor = Helpers.Colors.BarBackgroundColor,
BarTextColor = Color.FromArgb("#ffffff")
},
Flyout = new MyDrawerMenu(),
FlyoutLayoutBehavior = FlyoutLayoutBehavior.Popover
};
((App)Application.Current).MainPage = FlyoutPage;
}
上面的工作就像一个魅力。我的页面被正确地呈现,我看到了汉堡菜单。
大多数时候,我希望当用户点击某个项目时,“后退”按钮会显示在页面顶部。这是可行的。但是,有几个页面的后退按钮没有意义,所以我希望它被删除,而显示汉堡菜单。
以下是我的导航方式:
public async Task LaunchNextPage(Page page)
{
Page mdp = (((App)Application.Current).MainPage as FlyoutPage).Detail;
NavigationPage np = (NavigationPage)mdp;
NavigationPage.SetHasBackButton(page, false);
await np.PushAsync(page, true);
}
这段代码成功地导航到第二页。后退按钮按预期工作,并且NavigationPage.SetHasBackButton(page,false)
从屏幕顶部的导航栏中删除了后退按钮。
然而,我没有看到汉堡菜单。我仍然可以从左侧滑动并显示菜单,但我真的希望看到汉堡显示在页面顶部。
我应该注意到,在Xamarin. Forms中,这确实如我预期的那样工作。只有在迁移到MAUI时,我才看到这种行为。
任何帮助将不胜感激!
1条答案
按热度按时间w8rqjzmb1#
我无法找到一个好的方法来恢复默认的汉堡包按钮,而不清除页面堆栈,我不想对所有页面都这样做。所以我能够通过在需要时设置标题视图和复制导航栏来使其工作。
NavigationBar.xaml:
NavigationBar.xaml.cs:
希望这能对某些人有所帮助!