Adaptation plan for Avalonia's customized title bar in Windows 7 environment

Adaptation plan for Avalonia's customized title bar in Windows 7 environment

Detailed explanation of the root cause and perfect solution for the residual problem in the native title bar when Avalonia applies to customize the title bar under Windows 7, including complete code examples and version compatibility analysis

最后更新 7/23/2025 11:45 PM
沙漠尽头的狼
预计阅读 2 分钟
分类
Avalonia UI
标签
.NET C# Avalonia UI compatibility processing Avalonia

problem phenomenon

When using Avalonia to implement a custom title bar on Windows 7, you may encounter compatibility issues that cannot be hidden by the native title bar, resulting in abnormal interface display:

图1:Win7环境下标题栏异常显示效果

Figure 1: Abnormal display effect of title bar in Win7 environment

technical analysis

Here, I would like to thank you for your help from the WeChat [Avalonia Development and Exchange Group] group:

图2:微信群技术交流

Figure 2: WeChat group technical exchange

There are differences in the Avalonia framework's handling of window decorations in different Windows versions:

      • Windows 10/11 **: Modern window styles are supported by default, and custom title bars can hide native title bars normally
      • Windows 7 **: Due to system composer limitations, system decorations need to be explicitly disabled

SystemDecorations属性控制窗口边框和标题栏的显示行为,其枚举值包括:

  • Full:完整系统装饰(默认值)
  • BorderOnly:仅显示边框
  • None:完全禁用系统装饰
  • ResizeBorder:仅保留可调整大小的边框

solutions

通过在窗口初始化代码中显式设置SystemDecorations属性为None,可强制隐藏原生标题栏:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        // 关键设置:禁用系统装饰以支持自定义标题栏
        // 在Windows 7环境下必须显式设置,Win10+可省略
        if (OperatingSystem.IsWindows() && !OperatingSystem.IsWindowsVersionAtLeast(6, 2)) // Windows 7及以下
        {
            SystemDecorations = SystemDecorations.None;
        }
    }
}

After setting, the effect is as follows. The native title bar has been successfully hidden, and the custom title bar is displayed normally:

图3:应用修复后的标题栏显示效果

Figure 3: Display effect of the title bar after applying the repair

By the way, to support Win7 AOT running, don't forget to add the NuGet package:

<PackageReference Include="YY-Thunks" Version="1.1.8-Beta4" />
Keep Exploring

延伸阅读

更多文章