MAUI怎么实现自定义导航栏 MAUI Shell TitleView用法

admin 百科 8
MAUI自定义导航栏的核心是Shell.TitleView,它允许用任意XAML内容完全替换默认标题栏;需确保页面为Shell子页面,TitleView必须是ContentPage直接子元素,支持绑定与高度控制。

MAUI怎么实现自定义导航栏 MAUI Shell TitleView用法-第1张图片-佛山资讯网

MAUI 自定义导航栏的核心:Shell.TitleView

MAUI 中实现自定义导航栏,最标准、推荐的方式就是用 Shell.TitleView。它允许你完全替换默认的标题栏区域(包括标题文字、返回按钮等),用任意 XAML 内容(比如 StackLayout、Grid、Image、Button 等)来构建自己的导航栏外观和交互。

启用 TitleView 前要确认 Shell 结构

确保你的页面是 Shell 的子页面(即在 AppShell.xaml 中通过 FlyoutItem 或 TabBar 导航到该页),否则 TitleView 不生效。页面本身不需要继承 ShellContent,而是作为 ContentPage 放在 ShellContent.ContentTemplate 里。

  • AppShell.xaml 中类似:<shellcontent contenttemplate="{DataTemplate local:MyPage}"></shellcontent>
  • MyPage.xaml 是普通 ContentPage,顶部加上 Shell.TitleView 即可生效

在页面中使用 TitleView 的基本写法

直接在 ContentPage 根元素内添加 Shell.TitleView,里面放你想要的 UI:

标签: android go app ios

发布评论 0条评论)

还木有评论哦,快来抢沙发吧~