Skip to content

DevExpress-Examples/how-to-bind-accordioncontrol-to-hierarchical-data-structure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Accordion Control - Bind to Hierarchical Data Structure

This example binds our WPF Accordion Control to a hierarchical data structure.

Implementation Details

To display hierarchical data within the DevExpress WPF Accordion Control, bind the ItemsSource property to a collection populated with child items. Use the ChildrenPath property to specify collection name.

In this example, the Accordion Control is bound to a collection of "departments". Each department contains a collection of employees:

<dxa:AccordionControl
    ItemsSource="{Binding Departments}"
    ChildrenPath="Employees"
    SelectedItem="{Binding SelectedEmployee, Mode=TwoWay}"
    SelectionUnit="SubItem" />

MainViewModel exposes two bindable properties:

Departments – a collection of EmployeeDepartment objects grouped by department names.

SelectedEmployee – the employee selected in the Accordion Control.

At runtime, the view model loads employee data, groups it by department, and assigns the first available employee to the SelectedEmployee property:

var departments = DataHelper.GetEmployees()
    .GroupBy(x => x.GroupName)
    .Select(x => CreateEmployeeDepartment(x.Key, x.Take(10).ToArray()))
    .ToArray();

Departments = new ObservableCollection<EmployeeDepartment>(departments);
SelectedEmployee = Departments[0].Employees[0];

Each EmployeeDepartment object includes an Employees collection:

public class EmployeeDepartment {
    public string Name { get; set; }
    public ObservableCollection<Employee> Employees { get; set; }
}

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

.NET, WPF, DXAccordion for WPF

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5