How to: Create a Simple Application with the AccordionControl
- 6 minutes to read
This example demonstrates how to create a simple application with the AccordionControl.
See the Getting Started tutorial to learn more.
The image below shows the result:
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace DxAccordionGettingStarted {
public class MainWindowViewModel {
public MainWindowViewModel() {
var employeeDepartments = Stuff.GetStuff()
.GroupBy(x => x.Department)
.Select(x => new EmployeeDepartment(x.Key, x.ToArray()));
EmployeeDepartments = new ObservableCollection<EmployeeDepartment>(employeeDepartments.ToArray());
}
public ObservableCollection<EmployeeDepartment> EmployeeDepartments { get; set; }
}
public class EmployeeDepartment {
public string Name { get; set; }
public ObservableCollection<Employee> Employees { get; set; }
public EmployeeDepartment(string name, IEnumerable<Employee> employees) {
Name = name;
Employees = new ObservableCollection<Employee>(employees);
}
public override string ToString() {
return Name;
}
}
}
<dx:DXWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars"
xmlns:dxa="http://schemas.devexpress.com/winfx/2008/xaml/accordion"
xmlns:local="clr-namespace:DxAccordionGettingStarted"
x:Class="DxAccordionGettingStarted.MainWindow"
Title="MainWindow" Height="350" Width="525">
<dx:DXWindow.DataContext>
<local:MainWindowViewModel/>
</dx:DXWindow.DataContext>
<Grid>
<dxa:AccordionControl ItemsSource="{Binding EmployeeDepartments}" ChildrenPath="Employees"/>
</Grid>
</dx:DXWindow>
using System.Collections.Generic;
namespace DxAccordionGettingStarted {
public class Employee {
public int ID { get; set; }
public string Name { get; set; }
public string Position { get; set; }
public string Department { get; set; }
public override string ToString() {
return Name;
}
}
public static class Stuff {
public static List<Employee> GetStuff() {
List<Employee> stuff = new List<Employee>();
stuff.Add(new Employee() { ID = 1, Name = "Gregory S. Price", Department = "Management", Position = "President" });
stuff.Add(new Employee() { ID = 2, Name = "Irma R. Marshall", Department = "Marketing", Position = "Vice President" });
stuff.Add(new Employee() { ID = 3, Name = "John C. Powell", Department = "Operations", Position = "Vice President" });
stuff.Add(new Employee() { ID = 4, Name = "Christian P. Laclair", Department = "Production", Position = "Vice President" });
stuff.Add(new Employee() { ID = 5, Name = "Karen J. Kelly", Department = "Finance", Position = "Vice President" });
stuff.Add(new Employee() { ID = 6, Name = "Brian C. Cowling", Department = "Marketing", Position = "Manager" });
stuff.Add(new Employee() { ID = 7, Name = "Thomas C. Dawson", Department = "Marketing", Position = "Manager" });
stuff.Add(new Employee() { ID = 8, Name = "Angel M. Wilson", Department = "Marketing", Position = "Manager" });
stuff.Add(new Employee() { ID = 9, Name = "Bryan R. Henderson", Department = "Marketing", Position = "Manager" });
stuff.Add(new Employee() { ID = 10, Name = "Harold S. Brandes", Department = "Operations", Position = "Manager" });
stuff.Add(new Employee() { ID = 11, Name = "Michael S. Blevins", Department = "Operations", Position = "Manager" });
stuff.Add(new Employee() { ID = 12, Name = "Jan K. Sisk", Department = "Operations", Position = "Manager" });
stuff.Add(new Employee() { ID = 13, Name = "Sidney L. Holder", Department = "Operations", Position = "Manager" });
stuff.Add(new Employee() { ID = 14, Name = "James L. Kelsey", Department = "Production", Position = "Manager" });
stuff.Add(new Employee() { ID = 15, Name = "Howard M. Carpenter", Department = "Production", Position = "Manager" });
stuff.Add(new Employee() { ID = 16, Name = "Jennifer T. Tapia", Department = "Production", Position = "Manager" });
stuff.Add(new Employee() { ID = 17, Name = "Judith P. Underhill", Department = "Finance", Position = "Manager" });
stuff.Add(new Employee() { ID = 18, Name = "Russell E. Belton", Department = "Finance", Position = "Manager" });
return stuff;
}
}
}
Imports System.Collections.Generic
Namespace DxAccordionGettingStarted
Public Class Employee
Public Property ID() As Integer
Public Property Name() As String
Public Property Position() As String
Public Property Department() As String
Public Overrides Function ToString() As String
Return Name
End Function
End Class
Public NotInheritable Class Stuff
Private Sub New()
End Sub
Public Shared Function GetStuff() As List(Of Employee)
Dim stuff_Renamed As New List(Of Employee)()
stuff_Renamed.Add(New Employee() With { _
.ID = 1, _
.Name = "Gregory S. Price", _
.Department = "Management", _
.Position = "President" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 2, _
.Name = "Irma R. Marshall", _
.Department = "Marketing", _
.Position = "Vice President" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 3, _
.Name = "John C. Powell", _
.Department = "Operations", _
.Position = "Vice President" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 4, _
.Name = "Christian P. Laclair", _
.Department = "Production", _
.Position = "Vice President" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 5, _
.Name = "Karen J. Kelly", _
.Department = "Finance", _
.Position = "Vice President" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 6, _
.Name = "Brian C. Cowling", _
.Department = "Marketing", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 7, _
.Name = "Thomas C. Dawson", _
.Department = "Marketing", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 8, _
.Name = "Angel M. Wilson", _
.Department = "Marketing", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 9, _
.Name = "Bryan R. Henderson", _
.Department = "Marketing", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 10, _
.Name = "Harold S. Brandes", _
.Department = "Operations", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 11, _
.Name = "Michael S. Blevins", _
.Department = "Operations", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 12, _
.Name = "Jan K. Sisk", _
.Department = "Operations", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 13, _
.Name = "Sidney L. Holder", _
.Department = "Operations", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 14, _
.Name = "James L. Kelsey", _
.Department = "Production", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 15, _
.Name = "Howard M. Carpenter", _
.Department = "Production", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 16, _
.Name = "Jennifer T. Tapia", _
.Department = "Production", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 17, _
.Name = "Judith P. Underhill", _
.Department = "Finance", _
.Position = "Manager" _
})
stuff_Renamed.Add(New Employee() With { _
.ID = 18, _
.Name = "Russell E. Belton", _
.Department = "Finance", _
.Position = "Manager" _
})
Return stuff_Renamed
End Function
End Class
End Namespace
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Linq
Namespace DxAccordionGettingStarted
Public Class MainWindowViewModel
Public Sub New()
Dim employeeDepartments_Renamed = Stuff.GetStuff().GroupBy(Function(x) x.Department).Select(Function(x) New EmployeeDepartment(x.Key, x.ToArray()))
EmployeeDepartments = New ObservableCollection(Of EmployeeDepartment)(employeeDepartments_Renamed.ToArray())
End Sub
Public Property EmployeeDepartments() As ObservableCollection(Of EmployeeDepartment)
End Class
Public Class EmployeeDepartment
Public Property Name() As String
Public Property Employees() As ObservableCollection(Of Employee)
Public Sub New(ByVal name As String, ByVal employees As IEnumerable(Of Employee))
Me.Name = name
Me.Employees = New ObservableCollection(Of Employee)(employees)
End Sub
Public Overrides Function ToString() As String
Return Name
End Function
End Class
End Namespace