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

.NET 8 MAUI中如何修改AppShell菜单按钮背景色

如何修改.NET 8 MAUI中AppShell菜单按钮的背景色?

我想了解:

  • 是否有可直接使用的属性来修改.NET 8 MAUI中AppShell菜单按钮的背景色?
  • 是否可以通过自定义模板实现该需求?

最初尝试的模板方案

我曾在Platforms\Windows下的App.xaml中尝试以下模板:

<maui:MauiWinUIApplication.Resources>
    <DataTemplate x:Key="MauiAppTitleBarTemplate">
        <Grid>
            <Border Canvas.ZIndex="1" VerticalAlignment="Stretch" Background="#0366d6" Margin="0,0,0,0"></Border>
        </Grid>
    </DataTemplate>
</maui:MauiWinUIApplication.Resources>

需要修改背景色的AppShell菜单按钮

AppShell菜单按钮

期望实现的效果

期望的AppShell菜单按钮效果


编辑:2024-06-30:我已实现预期效果,此前的模板方式并非正确方案,正确的Platforms\Windows下App.xaml文件内容如下:

<maui:MauiWinUIApplication.Resources>
    <ResourceDictionary>
        <Style TargetType="ContentControl" x:Key="WindowChromeStyle">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ContentControl">
                        <Grid x:Name="LayoutRoot" Background="#0366d6">
                            <ContentPresenter x:Name="ClientAreaPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Foreground="{TemplateBinding Foreground}" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ResourceDictionary>
</maui:MauiWinUIApplication.Resources>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 19:42:45