You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET MAUI Shell Flyout Menu不显示,汉堡菜单及侧滑无效求助

.NET MAUI Shell Flyout菜单不显示汉堡按钮/滑动无效的解决方法

你的问题核心在于初始页面没有被包含在FlyoutItem中。当Shell直接渲染ShellContent(而非嵌套在FlyoutItem内)时,默认会将该页面视为独立于Flyout导航体系的页面,因此不会显示汉堡按钮,也不会响应侧边滑动操作。

解决办法

方法1:将所有页面纳入FlyoutItem体系

把初始的ShellContent放到FlyoutItem中,让所有页面都属于Flyout导航的一部分,这样Shell会自动渲染汉堡按钮并启用滑动触发:

<Shell
x:Class="Test.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Test"
Shell.FlyoutBehavior="Flyout"
>

<FlyoutItem Title="Home">
    <ShellContent
        Title="Test"
        ContentTemplate="{DataTemplate local:LoginPage}"
        Route="MainPage" />
</FlyoutItem>

<FlyoutItem Title="Lookup Items">
    <ShellContent ContentTemplate="{DataTemplate local:MenuPage}"/>
</FlyoutItem>
<FlyoutItem Title="Logout">
    <ShellContent ContentTemplate="{DataTemplate local:LoginPage}"/>
</FlyoutItem>
</Shell>

方法2:单独为初始页面启用Flyout

如果需要保留初始页面的独立结构,但仍要启用Flyout,可以在该页面的XAML或代码后台强制设置Flyout行为:

XAML方式(在LoginPage的根元素添加):

<ContentPage 
    ...
    Shell.FlyoutBehavior="Flyout">
    <!-- 页面内容 -->
</ContentPage>

代码后台方式(LoginPage构造函数中):

public LoginPage()
{
    InitializeComponent();
    Shell.SetFlyoutBehavior(this, FlyoutBehavior.Flyout);
}

额外检查点

  • 确保页面没有设置Shell.NavBarIsVisible="False",如果隐藏了导航栏,汉堡按钮也会被一同隐藏。
  • 确认Shell.FlyoutBehavior全局设置为Flyout(你已经设置了,这部分没问题)。

内容的提问来源于stack exchange,提问作者BitWiseByteDumb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 12:02:10