# RadioButton 自定义样式指南
RadioButton 的视觉表现通过 `ControlTheme` + Design Token 系统控制。以下介绍常见自定义方式。
---
## 1. 使用属性直接控制
最简单的方式是通过 RadioButton 的公共属性来控制外观:
```xml
Radio
Selected
Disabled
Disabled Checked
```
单选框组的排列和间距控制:
```xml
Option A
Option B
Option A
Option B
Option A
Option B
```
> 📖 完整示例参考:`controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/RadioButtonShowCase.axaml`
---
## 2. 通过 Style 覆盖样式
可以在 AXAML 中使用 `Style` 对 RadioButton 进行全局或局部样式覆盖:
### 全局统一间距
```xml
```
### 按状态定制
```xml
```
### 自定义指示器颜色
通过模板部件选择器定制 RadioIndicator 的视觉:
```xml
```
### 自定义文本间距
```xml
```
---
## 3. 通过 ControlTheme 完全替换主题
如果需要彻底替换 RadioButton 的模板和样式,可以定义自定义 `ControlTheme`:
```xml
自定义
```
> ⚠️ 注意:完全替换 ControlTheme 将丢失内置的波纹效果和选中动画。建议优先使用 Style 覆盖。
---
## 4. 控制动画行为
```xml
No Wave
No Animation
Option A
Option B
```
---
## 5. 禁用状态交互示例
```xml
Radio1
Radio2
toggle disabled
```
```csharp
public void ToggleDisabledStatus(object? sender, RoutedEventArgs args)
{
Radio1.IsEnabled = !Radio1.IsEnabled;
Radio2.IsEnabled = !Radio2.IsEnabled;
}
```
> 📖 参考:`controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/RadioButtonShowCase.axaml` 中 "Disabled" 示例。
---
## 样式选择器速查
> 说明:Avalonia 样式选择器中使用 `atom|RadioButton` 语法引用 `atom` XML 命名空间下的 `RadioButton` 类型,其中 `|` 是命名空间分隔符。
### RadioButton 选择器
| 选择器 | 说明 |
|---|---|
| `atom\|RadioButton` | 匹配所有 AtomUI RadioButton 实例 |
| `atom\|RadioButton:checked` | 匹配选中状态的单选框 |
| `atom\|RadioButton:unchecked` | 匹配未选中状态的单选框 |
| `atom\|RadioButton:pointerover` | 匹配鼠标悬浮状态 |
| `atom\|RadioButton:disabled` | 匹配禁用状态 |
| `atom\|RadioButton:focus-visible` | 匹配通过键盘获得焦点 |
### 模板部件选择器
| 选择器 | 说明 |
|---|---|
| `atom\|RadioButton /template/ atomc\|RadioIndicator#Indicator` | 圆形选中指示器 |
| `atom\|RadioButton /template/ ContentPresenter#ContentPresenter` | 文本内容区 |
| `atom\|RadioButton /template/ Border#Frame` | RadioButton 根框架 |
### RadioButtonGroup 选择器
| 选择器 | 说明 |
|---|---|
| `atom\|RadioButtonGroup` | 匹配所有 RadioButtonGroup 实例 |
| `atom\|RadioButtonGroup /template/ Border#Frame` | 匹配 RadioButtonGroup 根框架 |
| `atom\|RadioButtonGroup /template/ ItemsPresenter#PART_ItemsPresenter` | 匹配子项容器 |
### 组合选择器示例
| 选择器 | 说明 |
|---|---|
| `atom\|RadioButton:checked:not(:disabled)` | 非禁用的选中单选框 |
| `atom\|RadioButton:not(:checked):pointerover` | 悬浮中的未选中单选框 |
| `atom\|RadioButton:disabled:checked` | 禁用且选中的单选框 |
### 注意事项
- RadioButton 使用 `atomc` 命名空间前缀(`xmlns:atomc="https://atomui.net/common-controls"`)来引用内部控件如 `RadioIndicator`。在样式选择器中需使用 `atomc|RadioIndicator` 语法。
- 指示器是内部控件,只能通过模板部件选择器 `/template/` 访问。