Avalonia UI自定义无边框异形窗口:边框与阴影消除问题
在Avalonia UI中移除Windows 11窗口边框和阴影,仅保留自定义圆形内容
要解决Windows 11下Avalonia窗口仍残留边框、阴影的问题,只需调整核心属性并清理冗余配置:
- 必须添加
AllowTransparency="True"——这是Windows平台实现完全透明、消除系统阴影的关键开关 - 移除
ExtendClientArea相关属性(这类属性针对保留标题栏场景,和完全无装饰窗口冲突) - 确保
WindowState="Normal",避免最大化状态下的阴影残留
修改后的完整XAML代码:
<Window xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="avava.MainWindow" Width="200" Height="200" WindowStartupLocation="CenterScreen" Background="Transparent" TransparencyBackgroundFallback="Transparent" SystemDecorations="None" AllowTransparency="True" WindowState="Normal"> <Ellipse Fill="Green" Opacity="0.5" Width="150" Height="150" StrokeThickness="10" Stroke="Blue"/> </Window>
如果修改后仍有阴影残留,检查项目的.csproj文件,添加以下配置禁用Windows 11默认的Mica效果:
<PropertyGroup> <WindowsEnableMicaWindow>false</WindowsEnableMicaWindow> </PropertyGroup>
内容的提问来源于stack exchange,提问作者Yegor
相关产品推荐
相关产品推荐

