wpf-405007-controls-and-libraries-diagram-control-data-binding-generate-multi-level-diagrams.md
Both DiagramDataBindingBehavior and DiagramOrgChartBehavior allow you to generate diagrams with composite items: item lists, multi-level containers, etc.
View Example: Generate Diagrams with Grouped Items
Use one of the following properties to generate a multi-level diagram:
DiagramDataBindingBehaviorBase.ItemsPathSet this property to the name of the data field that contains the collection of nested data items.DiagramDataBindingBehaviorBase.ItemsSelector
Use this property to dynamically return collections of nested items based on custom logic.
<local:ChildrenSelector x:Key="childSelector"/>
<!-- ... -->
<dxdiag:DiagramDataBindingBehavior ItemsSelector="{StaticResource ResourceKey=childSelector}"/>
public class ChildrenSelector : IChildrenSelector {
public IEnumerable<object> GetChildren(object parent) {
if (parent is Department item)
return item.Employees;
else {
//...
}
}
}
Public Class ItemsSelector
Implements IChildrenSelector
Public Function GetChildren(ByVal parent As Object) As IEnumerable(Of Object) Implements IChildrenSelector.GetChildren
If TypeOf parent Is Department Then
Return CType(parent, Department).Employees
ElseIf
' ...
End If
End Function
End Class
You can use one of the following techniques to identify nested data items:
Assign the field name that uniquely identifies items to the DiagramDataBindingBehaviorBase.KeyMember property. Use this technique if the field name is the same for all nested levels.
Assign an object that returns item unique identifiers based on custom logic to the DiagramDataBindingBehaviorBase.KeySelector property. Use this technique if root and nested items have different identifier fields or to specify unique identifiers conditionally.
To generate different items based on the nested level, use the DiagramDataBindingBehaviorBase.ItemTemplateSelector property or choose items from TemplateDiagram in the DiagramDataBindingBehaviorBase.GenerateItem event handler.
The DiagramControl automatically arranges child items if you place them inside a DiagramList. If you use a DiagramContainer as a parent item, you should arrange its nested items manually.
Refer to the following help topic for more information: Define and Configure Generated Diagram Items.