# Window 自定义样式指南 Window 的视觉表现通过 `ControlTheme` + Design Token 系统控制。以下介绍几种常见的自定义方式。 --- ## 1. 使用属性直接控制 最简单的方式是通过 Window 的公共属性来控制外观: ```xml ``` > 📖 Gallery 主窗口使用范例:`controlgallery/AtomUIGallery/Workspace/Views/WorkspaceWindow.axaml` --- ## 2. 通过 Style 覆盖样式 可以在 AXAML 中使用 `Style` 对 Window 进行全局或局部样式覆盖: ### 自定义窗口背景色 ```xml ``` ### 自定义内容区域背景 ```xml ``` ### 自定义标题栏背景 ```xml ``` ### 平台差异化样式 ```xml ``` --- ## 3. 使用框架层实现高级视觉效果 ### 窗口级渐变背景 ```xml ``` ### 带不透明度的内容区背景图 ```xml ``` ### 使用模板定义框架层内容 ```xml ``` --- ## 4. 通过 ControlTheme 完全替换主题 如果需要彻底替换 Window 的模板和样式,可以定义自定义 `ControlTheme`: ```xml ``` > ⚠️ 注意:完全替换 ControlTheme 将丢失内置的媒体查询、对话框层管理、窗口缩放器等功能。建议优先使用 Style 覆盖和框架层实现自定义效果。 --- ## 样式选择器速查 > 说明:Avalonia 样式选择器中使用 `atom|Window` 语法引用 `atom` XML 命名空间下的 `Window` 类型,其中 `|` 是命名空间分隔符。 ### 按控件类型选择 | 选择器 | 说明 | |---|---| | `atom\|Window` | 匹配所有 AtomUI Window 实例 | | `atom\|WindowTitleBar` | 匹配窗口标题栏控件 | ### 按操作系统选择 | 选择器 | 说明 | |---|---| | `atom\|Window[OsType=Windows]` | 匹配 Windows 平台的窗口 | | `atom\|Window[OsType=Linux]` | 匹配 Linux 平台的窗口 | | `atom\|Window[OsType=macOS]` | 匹配 macOS 平台的窗口 | ### 按窗口状态选择 | 选择器 | 说明 | |---|---| | `atom\|Window[WindowState=Normal]` | 匹配正常状态的窗口 | | `atom\|Window[WindowState=Maximized]` | 匹配最大化状态的窗口 | | `atom\|Window[WindowState=FullScreen]` | 匹配全屏状态的窗口 | | `atom\|Window[WindowState=Minimized]` | 匹配最小化状态的窗口 | ### 按属性选择 | 选择器 | 说明 | |---|---| | `atom\|Window[IsTitleBarVisible=False]` | 匹配隐藏了标题栏的窗口 | | `atom\|Window[Topmost=True]` | 匹配置顶的窗口 | | `atom\|Window[CanResize=False]` | 匹配不可调整大小的窗口 | ### 模板内部件选择 | 选择器 | 说明 | |---|---| | `atom\|Window /template/ Border#WindowFrame` | 窗口主框架 Border | | `atom\|Window /template/ ContentPresenter#WindowFrameLayer` | 窗口级框架背景层 | | `atom\|Window /template/ ContentPresenter#TitleBarFrameLayer` | 标题栏框架背景层 | | `atom\|Window /template/ ContentPresenter#ContentFrameLayer` | 内容区框架背景层 | | `atom\|Window /template/ Border#ContentFrame` | 内容框架(Container Query 容器) | | `atom\|Window /template/ DockPanel#PART_ContentLayout` | 内容布局容器 | ### 组合选择器示例 | 选择器 | 说明 | |---|---| | `atom\|Window[OsType=Linux][WindowState=Normal]` | Linux 平台正常状态的窗口(有圆角和边框) | | `atom\|Window[WindowState=FullScreen], atom\|Window[WindowState=Maximized]` | 全屏或最大化时(清除圆角和边框) | | `atom\|Window:not([OsType=Linux])` | 非 Linux 平台的窗口(无自定义圆角) |