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

如何移除面向Windows 11的.NET MAUI中标题按钮覆盖层视觉瑕疵?

解决MAUI Windows端标题按钮区域视觉瑕疵问题

当将window.ExtendsContentIntoTitleBar设为true并启用DesktopAcrylicBackdrop亚克力背景时,标题栏按钮区域出现视觉异常,核心原因是标题栏按钮的默认背景未适配亚克力效果。可通过以下代码修复:

修复代码

修改MauiProgram.cs中窗口生命周期事件的实现:

builder.ConfigureLifecycleEvents(events =>
{
#if WINDOWS
    events.AddWindows(windowsLifecycleBuilder =>
    {
        windowsLifecycleBuilder.OnWindowCreated(window =>
        {
            window.ExtendsContentIntoTitleBar = true;
            window.SystemBackdrop = new DesktopAcrylicBackdrop();

            var titleBar = window.AppWindow.TitleBar;
            // 设置按钮背景为透明,适配亚克力效果
            titleBar.ButtonBackgroundColor = Colors.Transparent;
            // 设置按钮默认前景色,可根据主题调整
            titleBar.ButtonForegroundColor = Colors.Black;

            // 窗口激活状态变化时调整按钮颜色,优化视觉体验
            window.Activated += (sender, args) =>
            {
                titleBar.ButtonForegroundColor = args.WindowActivationState == Microsoft.UI.Windowing.WindowActivationState.Deactivated
                    ? Colors.Gray
                    : Colors.Black;
            };
        });
    });
#endif
});

补充说明

  • 若问题仍存在,可尝试延迟配置标题栏(比如在窗口加载完成后执行相关代码),避免生命周期时机冲突。
  • 适配深色模式时,需对应调整ButtonForegroundColor的颜色值,确保按钮在不同主题下清晰可见。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 23:52:17