# Timeline 自定义样式指南 Timeline 的视觉表现通过 `ControlTheme` + Design Token 系统控制。以下介绍几种常见的自定义方式。 --- ## 1. 通过属性直接控制 最简单的方式是通过 Timeline 和 TimelineItem 的公共属性来控制外观: ```xml 事件一 事件二 成功 失败 未完成 进行中 左侧内容 右侧内容 创建项目 正式开源 已完成事件 ``` --- ## 2. 通过 Style 覆盖样式 ### 全局统一间距 ```xml ``` ### 按位置定制 ```xml ``` ### 标签文本样式 ```xml ``` ### 内容区域样式 ```xml ``` --- ## 3. 通过 ControlTheme 完全替换主题 > ⚠️ 注意:完全替换 ControlTheme 需要理解 Timeline 的三层模板结构(Timeline / TimelineItem / TimelineIndicator),建议优先使用 Style 覆盖。 ```xml ``` --- ## 样式选择器速查 > 说明:Avalonia 样式选择器中使用 `atom|Timeline` 语法引用 `atom` XML 命名空间下的类型,其中 `|` 是命名空间分隔符。 ### Timeline 选择器 | 选择器 | 说明 | |---|---| | `atom\|Timeline` | 匹配所有 Timeline 实例 | | `atom\|Timeline[Mode=Alternate]` | 匹配交替布局的时间轴 | | `atom\|Timeline[Mode=Right]` | 匹配右对齐的时间轴 | | `atom\|Timeline[IsReverse=True]` | 匹配反转排列的时间轴 | ### TimelineItem 位置伪类选择器 | 选择器 | 说明 | |---|---| | `atom\|TimelineItem:order-first` | 第一个节点 | | `atom\|TimelineItem:order-last` | 最后一个节点 | | `atom\|TimelineItem:order-odd` | 奇数位置节点(交替布局中的右侧内容) | | `atom\|TimelineItem:order-even` | 偶数位置节点(交替布局中的左侧内容) | | `atom\|TimelineItem:pending-item` | 待办节点 | ### TimelineItem 模板部件选择器 | 选择器 | 说明 | |---|---| | `atom\|TimelineItem /template/ atom\|TextBlock#Label` | 标签文本部件 | | `atom\|TimelineItem /template/ ContentPresenter#ContentPresenter` | 内容呈现部件 | | `atom\|TimelineItem /template/ atomc\|TimelineIndicator#Indicator` | 指示器部件 | ### 组合选择器示例 | 选择器 | 说明 | |---|---| | `atom\|TimelineItem:order-first:not(:pending-item)` | 非待办的第一个节点 | | `atom\|TimelineItem:pending-item /template/ ContentPresenter#ContentPresenter` | 待办节点的内容区域 |