syncfusion-wpf-accordion
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing SfAccordion (WPF)
实现SfAccordion(WPF)
When to Use This Skill
何时使用本技能
Use this skill when the user needs to:
- Build collapsible/expandable section UI in WPF
- Display categorized content with expand-on-demand behavior
- Create Outlook-style, FAQ-style, or settings-panel accordion layouts
- Bind a business object collection to an accordion
- Control how many items can be expanded simultaneously
- Customize accordion item headers, content, expander buttons, or animation
当用户需要以下功能时使用本技能:
- 在WPF中构建可折叠/展开区域UI
- 显示支持按需展开的分类内容
- 创建Outlook样式、FAQ样式或设置面板式的手风琴布局
- 将业务对象集合绑定到手风琴控件
- 控制可同时展开的项数量
- 自定义手风琴项的标题、内容、展开按钮或动画
Component Overview
组件概述
SfAccordion (ItemsControl)
└── SfAccordionItem (×N) (HeaderedContentControl)
├── Header — always visible (collapsed & expanded)
└── Content — visible only when expanded (IsSelected=true)Assembly:
Namespace:
XAML Schema:
Syncfusion.SfAccordion.WPFNamespace:
Syncfusion.Windows.Controls.LayoutXAML Schema:
http://schemas.syncfusion.com/wpfSfAccordion (ItemsControl)
└── SfAccordionItem (×N) (HeaderedContentControl)
├── Header — always visible (collapsed & expanded)
└── Content — visible only when expanded (IsSelected=true)程序集:
命名空间:
XAML架构:
Syncfusion.SfAccordion.WPF命名空间:
Syncfusion.Windows.Controls.LayoutXAML架构:
http://schemas.syncfusion.com/wpfDocumentation and Navigation Guide
文档与导航指南
Getting Started
入门指南
📄 Read: references/getting-started.md
- Assembly reference and NuGet setup
- XAML and C# control creation
- Basic SfAccordionItem with Header and Content
- Themes with SfSkinManager
📄 阅读: references/getting-started.md
- 程序集引用与NuGet配置
- XAML和C#控件创建
- 带有Header和Content的基础SfAccordionItem
- 使用SfSkinManager设置主题
Populating Items
填充项
📄 Read: references/populating-items.md
- Declarative items via collection
Items - Data binding via
ItemsSource - Model + ViewModel + ObservableCollection
- for quick headers
DisplayMemberPath - /
HeaderTemplateHeaderTemplateSelector - /
ContentTemplateContentTemplateSelector
📄 阅读: references/populating-items.md
- 通过集合声明式添加项
Items - 通过进行数据绑定
ItemsSource - 模型+视图模型+ObservableCollection
- 使用快速设置标题
DisplayMemberPath - /
HeaderTemplateHeaderTemplateSelector - /
ContentTemplateContentTemplateSelector
Selecting Items
选择项
📄 Read: references/selecting-items.md
- — select by index
SelectedIndex - — select by instance (TwoWay binding)
SelectedItem - /
SelectedItems— read-only collectionsSelectedIndices - on individual items
IsSelected - /
SelectAll()methodsUnselectAll() - /
SelectedItemsChangedeventsSelectionChanged
📄 阅读: references/selecting-items.md
- — 通过索引选择
SelectedIndex - — 通过实例选择(双向绑定)
SelectedItem - /
SelectedItems— 只读集合SelectedIndices - 单个项上的属性
IsSelected - /
SelectAll()方法UnselectAll() - /
SelectedItemsChanged事件SelectionChanged
Selection Mode
选择模式
📄 Read: references/selection-mode.md
- — exactly one expanded (default)
One - — multiple expanded, at least one required
OneOrMore - — at most one, all can collapse
ZeroOrOne - — multiple, all can collapse
ZeroOrMore - Decision guide: choosing the right mode
📄 阅读: references/selection-mode.md
- — 仅允许展开一个项(默认)
One - — 允许多个项展开,至少保留一个展开状态
OneOrMore - — 最多展开一个项,所有项均可折叠
ZeroOrOne - — 允许多个项展开,所有项均可折叠
ZeroOrMore - 决策指南:选择合适的模式
Appearance and Styling
外观与样式
📄 Read: references/appearance-and-styling.md
- — highlight color
AccentBrush - /
HeaderTemplateContentTemplate - — expander arrow customization
AccordionButtonStyle - — per-item styling
ItemContainerStyle - Animation enable/disable
- SfSkinManager themes
📄 阅读: references/appearance-and-styling.md
- — 高亮颜色
AccentBrush - /
HeaderTemplateContentTemplate - — 展开箭头自定义
AccordionButtonStyle - — 逐项样式设置
ItemContainerStyle - 启用/禁用动画
- SfSkinManager主题
Quick Start
快速入门
xaml
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
<syncfusion:SfAccordion Width="300" Height="200">
<syncfusion:SfAccordionItem Header="WPF"
Content="Essential Studio for WPF"/>
<syncfusion:SfAccordionItem Header="Silverlight"
Content="Essential Studio for Silverlight"/>
<syncfusion:SfAccordionItem Header="WinRT"
Content="Essential Studio for WinRT" IsSelected="True"/>
</syncfusion:SfAccordion>csharp
using Syncfusion.Windows.Controls.Layout;
SfAccordion accordion = new SfAccordion();
accordion.Items.Add(new SfAccordionItem { Header = "WPF", Content = "Essential Studio for WPF" });
accordion.Items.Add(new SfAccordionItem { Header = "Silverlight", Content = "Essential Studio for Silverlight" });
accordion.Items.Add(new SfAccordionItem { Header = "WinRT", Content = "Essential Studio for WinRT", IsSelected = true });
this.Content = accordion;xaml
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
<syncfusion:SfAccordion Width="300" Height="200">
<syncfusion:SfAccordionItem Header="WPF"
Content="Essential Studio for WPF"/>
<syncfusion:SfAccordionItem Header="Silverlight"
Content="Essential Studio for Silverlight"/>
<syncfusion:SfAccordionItem Header="WinRT"
Content="Essential Studio for WinRT" IsSelected="True"/>
</syncfusion:SfAccordion>csharp
using Syncfusion.Windows.Controls.Layout;
SfAccordion accordion = new SfAccordion();
accordion.Items.Add(new SfAccordionItem { Header = "WPF", Content = "Essential Studio for WPF" });
accordion.Items.Add(new SfAccordionItem { Header = "Silverlight", Content = "Essential Studio for Silverlight" });
accordion.Items.Add(new SfAccordionItem { Header = "WinRT", Content = "Essential Studio for WinRT", IsSelected = true });
this.Content = accordion;Common Patterns
常见模式
| Scenario | Approach |
|---|---|
| Multiple sections, one open at a time | |
| FAQ where multiple can be open | |
| Data-driven content | |
| Highlight active item color | |
| Custom expander arrow | |
| Slow expand/collapse animation | |
| Track which items are expanded | |
| 场景 | 实现方式 |
|---|---|
| 多区域,同一时间仅展开一个 | |
| 允许多个区域展开的FAQ场景 | |
| 数据驱动内容 | |
| 高亮激活项颜色 | |
| 自定义展开箭头 | 在 |
| 缓慢的展开/折叠动画 | 在 |
| 跟踪已展开的项 | |
Key Properties
关键属性
| Property | Type | Description |
|---|---|---|
| | One / OneOrMore / ZeroOrOne / ZeroOrMore |
| | Index of most recently selected item |
| | Instance of most recently selected item |
| read-only | All currently selected item instances |
| read-only | All currently selected item indices |
| | Data collection binding |
| | Shared header template for all items |
| | Shared content template for all items |
| | Per-item header template |
| | Per-item content template |
| | Accent color for item highlight |
| | Style applied to each |
SfAccordionItem properties:
| Property | Description |
|---|---|
| Always-visible item header |
| Visible when item is expanded |
| |
| Read-only; |
| Style for the expander toggle button |
| 属性 | 类型 | 说明 |
|---|---|---|
| | One / OneOrMore / ZeroOrOne / ZeroOrMore |
| | 最近选中项的索引 |
| | 最近选中项的实例 |
| 只读 | 当前所有选中项的实例 |
| 只读 | 当前所有选中项的索引 |
| | 数据集合绑定 |
| | 所有项共享的标题模板 |
| | 所有项共享的内容模板 |
| | 逐项设置标题模板 |
| | 逐项设置内容模板 |
| | 项高亮的强调色 |
| | 应用于每个 |
SfAccordionItem属性:
| 属性 | 说明 |
|---|---|
| 始终可见的项标题 |
| 项展开时可见的内容 |
| |
| 只读; |
| 展开切换按钮的样式 |