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

.NET MAUI浅色模式下汉堡图标(FlyoutIcon)颜色无法更改的技术求助

.NET MAUI FlyoutIcon 主题色切换失效的解决办法

问题根源

Shell 默认会给 FlyoutIcon 应用全局 tint 颜色(通常是白色),直接设置图片或使用 AppThemeBinding 会被这个默认 tint 覆盖,导致颜色不生效。以下是三种可行的解决方式:


方法1:用 FontImageSource 替代图片资源

字体图标不受默认 tint 影响,能直接通过 AppThemeBinding 控制颜色:

<Shell.FlyoutIcon>
    <FontImageSource
        Glyph="&#xe5d2;" <!-- 汉堡图标对应的字体编码,以Material Icons为例 -->
        FontFamily="MaterialIcons"
        Color="{AppThemeBinding Light=Black, Dark=White}" />
</Shell.FlyoutIcon>
  • 确保项目已引入对应字体(如Material Icons),并在 Resources/Styles/Styles.xaml 中注册字体族。

方法2:用ContentView包裹图片,绕过默认tint

Shell 不会自动对ContentView内部的Image应用tint,因此颜色设置会生效:

<Shell.FlyoutIcon>
    <ContentView>
        <Image>
            <Image.Source>
                <FileImageSource File="hamburger_icon.png" />
            </Image.Source>
            <Image.Color>
                <AppThemeBinding Light="Black" Dark="White" />
            </Image.Color>
        </Image>
    </ContentView>
</Shell.FlyoutIcon>

方法3:修改Shell全局样式,覆盖默认前景色

在 Resources/Styles/Styles.xaml 中添加Shell样式,直接控制FlyoutIcon的tint颜色:

<Style TargetType="Shell">
    <Setter Property="FlyoutIconForegroundColor" Value="{AppThemeBinding Light=Black, Dark=White}" />
</Style>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 06:15:19