Skip to content

Commit 6225801

Browse files
Add final changes after review (fresh eye)
1 parent 7756fcd commit 6225801

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

Readme.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,60 @@
77

88
# WPF Accordion Control - Bind to a data source that contains hierarchical data objects of different types
99

10-
This example binds the [`AccordionControl`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl) to data objects of different types using the [`AccordionControl.ChildrenSelector`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector.property) property.
10+
This example binds the WPF [`AccordionControl`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl) to a hierarchical data structure that includes objects of different types. Use this technique when your data model does not expose a unified child collection (for instance, when parent and child objects do not share a common base class).
1111

12-
Refer to the [Data Binding](https://documentation.devexpress.com/WPF/118635/Controls-and-Libraries/Navigation-Controls/Accordion-Control/Data-Binding) topic for more information.
12+
The implementation leverages the [`ChildrenSelector`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector) property to retrieve child items at runtime. The standard [`ChildrenPath`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenPath) property cannot traverse mixed-type hierarchies. The [`ChildrenSelector`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector) property delegates child resolution to your custom logic.
1313

1414
## Implementation details
1515

16-
The [`AccordionControl`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl) control uses the [`ChildrenSelector`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector) property to bind a flat list of `Category` objects. Each `Category` contains a collection of `Item` objects in its `Items` property.
16+
### Data Structure
1717

18-
To build a hierarchical view, the [`AccordionControl`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl) needs to access child items dynamically. However, the data structure uses different object types (`Category` and `Item`) that do not share a common base class with a unified `Children` property. In this reason you cannot use the [`ChildrenPath`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenPath) property to specify the child collection name.
18+
The [`AccordionControl`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl) binds to a flat list of `Category` objects. Each `Category` contains a collection of `Item` objects in its `Items` property.
1919

20-
The [`AccordionControl`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl) control uses the [`ChildrenSelector`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector) property, which accepts a custom implementation of the `IChildrenSelector` interface. This technique allows the control to selectively return child items only for specific types:
20+
```csharp
21+
public class Category {
22+
public string CategoryName { get; set; }
23+
public ObservableCollection<Item> Items { get; set; }
24+
}
25+
26+
public class Item {
27+
public string ItemName { get; set; }
28+
}
29+
```
30+
31+
### Custom Children Selector
32+
33+
The custom selector (`MySelector`) implements the `IChildrenSelector` interface. The selector returns child items only for `Category` objects:
2134

2235
```csharp
2336
public class MySelector : IChildrenSelector {
2437
public IEnumerable SelectChildren(object item) {
25-
if (item is Category)
26-
return ((Category)item).Items;
38+
if (item is Category category)
39+
return category.Items;
2740
return null;
2841
}
2942
}
3043
```
3144

32-
In XAML, the selector is declared as a static resource and assigned to the [`AccordionControl.ChildrenSelector`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector) property:
45+
### XAML Configuration
46+
47+
Register the selector as a resource and assign it to the [`AccordionControl.ChildrenSelector`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector) property:
3348

3449
```xaml
3550
<local:MySelector x:Key="mySelector" />
36-
3751
<dxa:AccordionControl
3852
ItemsSource="{Binding MyData.Categories}"
3953
ChildrenSelector="{StaticResource mySelector}" />
4054
```
4155

42-
The [`AccordionControl`](https://docs.devexpress.com/WPF/118347/controls-and-libraries/navigation-controls/accordion-control) uses data templates to display `Category` and `Item` objects:
56+
### Data Templates
57+
58+
Define templates to display `Category` and `Item` objects:
4359

4460
```xaml
4561
<DataTemplate DataType="{x:Type local:Category}">
4662
<TextBlock Text="{Binding CategoryName}" />
4763
</DataTemplate>
48-
4964
<DataTemplate DataType="{x:Type local:Item}">
5065
<TextBlock Text="{Binding ItemName}" />
5166
</DataTemplate>

0 commit comments

Comments
 (0)