Skip to main content
All docs
V24.1

Generate Multi-Level Diagrams

  • 2 minutes to read

Both DiagramDataBindingBehavior and DiagramOrgChartBehavior allow you to generate diagrams with composite items: item lists, multi-level containers, etc.

WPF Diagram - Generate Containers with Shapes

View Example: Generate Diagrams with Grouped Items

Use one of the following properties to generate a multi-level diagram:

DiagramDataBindingBehaviorBase.ItemsPath
Set 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 {
            //...
        }
    }
}

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.

    <dxdiag:DiagramDataBindingBehavior KeyMember="ItemId"/>
    
  • 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.

    <local:KeySelector x:Key="keySelector"/>
    <!-- ... -->
    <dxdiag:DiagramDataBindingBehavior KeySelector="{StaticResource ResourceKey=keySelector}"/>
    
    public class KeySelector : IKeySelector {
        object IKeySelector.GetKey(object obj) {
            if (obj is Department department)
                return department.DepartmentId;
            else if (obj is Employee employee)
                return employee.EmployeeId;
            else {
                //...
            }
        }
    }
    

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.