MAUI新生5.4-内容页ShellContent

ShellContent是Shell视觉层次结构中,最终承载内容页的构件,Shell > FlyoutItem|TabBar > Tab > ShellContent > View。

 

一、按需加载内容页和应用启动时加载内容页

1、按需加载内容页。导航发生时,才加载内容页,按需创建。

【<ShellContent Title="Dogs"  ContentTemplate="{DataTemplate views:DogsPage}" />】

2、应用启动时加载内容页。应用启动时,加载全部内容页,对应用启动会有性能影响。

<ShellContent Title="Dogs"> <views:DogsPage /> </ShellContent>

 

 

二、页面样式外观的设置

1、在Shell中设置页面样式,针对所有内容页

复制代码
<!--背景色、前景色、标题颜色、禁用颜色、未选定颜色-->
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
       x:Class="Xaminals.AppShell"
       BackgroundColor="#455A64"
       ForegroundColor="White"
       TitleColor="White"
       DisabledColor="#B4FFFFFF"
       UnselectedColor="#95FFFFFF">
</Shell>
复制代码

2、可以在内容页中,重写样式外观

<ContentPage ...
             Shell.BackgroundColor="Gray"
             Shell.ForegroundColor="White"
             Shell.TitleColor="Blue"
             Shell.DisabledColor="#95FFFFFF"
             Shell.UnselectedColor="#B4FFFFFF">
</ContentPage>

 

 

三、内容页显示模式

1、内容页显示模式有以下几种:NotAnimated/Animated/Modal/ModalAnimated/ModalNotAnimated,是否有动画效果、是否以Modal方式

2、设置方式:

<ContentPage ...
             Shell.PresentationMode="Modal">
    ...             
</ContentPage>

 

 

四、导航栏的设置

复制代码
<!--导航栏阴影-->
<ContentPage ...
             Shell.NavBarHasShadow="true">
    ...
</ContentPage>

<!--是否禁用导航栏-->
<ContentPage ...
             Shell.NavBarIsVisible="false">
    ...
</ContentPage>

<!--在导航栏中自定义视图-->
<ContentPage ...>
    <Shell.TitleView>
        <Image Source="logo.png"
               HorizontalOptions="Center"
               VerticalOptions="Center" />
    </Shell.TitleView>
    ...
</ContentPage>
复制代码

 

posted @   functionMC  阅读(1154)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示