In the previous tutorial (Setting a composite node) we examined how to create composite node and several components. In this example we will create a composite node with the same component structure but instead of defining the components in code we will load them from XML. Here is the XML equivalent to the component hierarchy created in the previous tutorial.
XML
![]() |
---|
<StackPanel Orientation="Horizontal" Spacing="1"> |
Assign the above XML to a string variable named xmlContent. Then the code that creates the composite node and loads the above XML looks like this:
C#
![]() |
---|
CompositeNode node = new CompositeNode(diagram1); |
Visual Basic
![]() |
---|
Dim node As New CompositeNode(diagram1) |
Running the tutorial will yield the same result yet the declaration of the component hierarchy is much more compact.