You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# WPF Accordion Control - Bind to data through the ChildrenSelector property
8
+
# WPF Accordion Control - Bind to a data source that contains hierarchical data objects of different types
9
9
10
-
This example binds the [AccordionControl](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.class) to data using the [AccordionControl.ChildrenSelector](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector.property) property.
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.
11
11
12
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.
13
13
14
14
## Implementation details
15
15
16
-
In this example, the [AccordionControl](https://docs.devexpress.com/WPF/118347/controls-and-libraries/navigation-controls/accordion-control) is bound to a flat list of `Category` objects. Each `Category`stores a collection of `Item` objects in its `Items` property.
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.
17
17
18
-
To build a hierarchical view from the flat structure, the [AccordionControl](https://docs.devexpress.com/WPF/118347/controls-and-libraries/navigation-controls/accordion-control) uses the [`ChildrenSelector`](https://documentation.devexpress.com/WPF/DevExpress.Xpf.Accordion.AccordionControl.ChildrenSelector.property) property. This property is set to a custom implementation of the `IChildrenSelector` interface:
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.
19
+
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:
19
21
20
22
```csharp
21
23
publicclassMySelector : IChildrenSelector {
@@ -27,7 +29,7 @@ public class MySelector : IChildrenSelector {
27
29
}
28
30
```
29
31
30
-
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) property:
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:
31
33
32
34
```xaml
33
35
<local:MySelectorx:Key="mySelector" />
@@ -37,7 +39,7 @@ In XAML, the selector is declared as a static resource and assigned to the [Acco
37
39
ChildrenSelector="{StaticResource mySelector}" />
38
40
```
39
41
40
-
The [AccordionControl](https://docs.devexpress.com/WPF/118347/controls-and-libraries/navigation-controls/accordion-control) uses data templates to display `Category` and `Item` objects:
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:
41
43
42
44
```xaml
43
45
<DataTemplateDataType="{x:Type local:Category}">
@@ -64,6 +66,7 @@ The [AccordionControl](https://docs.devexpress.com/WPF/118347/controls-and-libra
-[ WPF Accordion Control - Bind to Hierarchical Data Structure](https://github.com/DevExpress-Examples/wpf-accordion-bind-to-hierarchical-data-structure)
68
71
-[WPF MVVM Framework - Use View Models Generated at Compile Time](https://github.com/DevExpress-Examples/wpf-mvvm-framework-view-model-generator)
69
72
-[WPF Dock Layout Manager - Bind the View Model Collection with LayoutAdapters](https://github.com/DevExpress-Examples/wpf-docklayoutmanager-bind-view-model-collection-with-layoutadapters)
0 commit comments