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:

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:

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:

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" />