Skip to content

Binds the WPF Accordion Control to a data source that contains hierarchical data objects of different types.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/wpf-accordion-bind-to-hierarchical-objects-of-different-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Accordion Control - Bind to a Data Source that Contains Hierarchical Data Objects of Different Types

This example binds the WPF 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).

The implementation leverages the ChildrenSelector property to retrieve child items at runtime. The standard ChildrenPath property cannot traverse mixed-type hierarchies. The ChildrenSelector property delegates child resolution to your custom logic.

Implementation Details

Data Structure

The AccordionControl binds to a flat list of Category objects. Each Category contains a collection of Item objects in its Items property.

public class Category {
    public string CategoryName { get; set; }
    public ObservableCollection<Item> Items { get; set; }
}

public class Item {
    public string ItemName { get; set; }
}

Custom Children Selector

The custom selector (MySelector) implements the IChildrenSelector interface. The selector returns child items only for Category objects:

public class MySelector : IChildrenSelector {
    public IEnumerable SelectChildren(object item) {
        if (item is Category category)
            return category.Items;
        return null;
    }
}

XAML Configuration

Register the selector as a resource and assign it to the AccordionControl.ChildrenSelector property:

<local:MySelector x:Key="mySelector" />
<dxa:AccordionControl
    ItemsSource="{Binding MyData.Categories}"
    ChildrenSelector="{StaticResource mySelector}" />

Data Templates

Define templates to display Category and Item objects:

<DataTemplate DataType="{x:Type local:Category}">
    <TextBlock Text="{Binding CategoryName}" />
</DataTemplate>
<DataTemplate DataType="{x:Type local:Item}">
    <TextBlock Text="{Binding ItemName}" />
</DataTemplate>

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Binds the WPF Accordion Control to a data source that contains hierarchical data objects of different types.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •