This diagram demonstrates the expansion of a tree where nodes are only created "on-demand", when the user clicks on the "expand" Button. As you expand the tree, it automatically performs a force-directed layout, which will make some room for the additional nodes.
When the user clicks on the "expand" Button, the button click event handler finds the corresponding data object by going up the visual tree to find the Node via the GraphObject.part property and then getting the node data that the Node is bound to via Part.data. If everExpanded is false, the code creates a random number of child data for that node, each with a random color property. Then the button click event handler changes the value of Node.isExpandedTree, thereby expanding or collapsing the node.
Some initial node expansions result in there being no children at all. In this case the Button is made invisible.
The diagram's Diagram.layout is an instance of ForceDirectedLayout. The standard conditions under which the layout will be performed include when nodes or links or group-memberships are added or removed from the model, or when they change visibility. In this case that means that when the user expands or collapses a node, another force-directed layout occurs again, even upon repeated expansions or collapses.