Using TargetTypeName="Node" uses the ItemTemplate and outputs the ff
Hello,
There are two other options you have.
1) You could bind the tree to a collection of Folders and set the global layout to look for the Folders with the corresponding Key set to collection of child nodes thereby eliminating the need to add the collection to the Node class:
<ig:XamDataTree.GlobalNodeLayouts >
<ig:NodeLayout Key="Children" TargetTypeName="Folder" DisplayMemberPath="Text"/>
</ig:XamDataTree.GlobalNodeLayouts>
2) You can bind the Grid to the collection of nodes using a nested layout instead of using GlobalNodeLayout
<ig:XamDataTree HorizontalAlignment="Left" Name="xamDataTree1" VerticalAlignment="Top"
DisplayMemberPath="Text">
<ig:XamDataTree.NodeLayouts>
<ig:NodeLayout Key="Children" DisplayMemberPath="Text" TargetTypeName="Node">
<ig:NodeLayout.NodeLayouts>
<ig:NodeLayout Key="Children" DisplayMemberPath="Text"
TargetTypeName="Node">
</ig:NodeLayout>
</ig:NodeLayout.NodeLayouts>
</ig:XamDataTree.NodeLayouts>
</ig:XamDataTree>
Valerie
Thanks for the new sample.
Based on all the info provided, it seems there is no way to implement a recursive NodeLayout given the original class structure I posted:
1. Node - base class of Folder and File, no list of objects
2. Folder - container class that inherits from Node, has list of Node objects (that can either be Folder or File)
3. File - leaf class that inherits from Node, no list of objects
2 possible workarounds illustrated by the samples are to:
a. add a list of Folder objects to the Folder class (which would introduce additional Nodes and Folders levels)
b. add a list of Node objects to the Node class (which kind of breaks the Composite design pattern because File class does not need to have a list of objects)
Please confirm if my understanding is correct.
When using a collection with multiple sub collections, there is no way to eliminate the middle layer (headers for folders and files). However, you can setup your collection to hold Nodes which are either are of type File or Folder. When doing this, the tree will see the type as type Node and will use the Node Layout with TargetTypeName = Node. Additionally since it is using the Node to determine the Layout the Node class must contain the collection in order to show the sub-nodes. I have attached a sample of this. When doing this you can control the look of the nodes by creating different content by using a converter.
Please see attached sample.
Thanks for sample Valerie.
However I noticed that to get it to work, Folder had to contain an additional list specific for the Folder objects. In terms of design, I think this is unnecessary since the list of Node objects already allows for both Folder and File types because of the inheritance relationship. Another issue is the display of "Nodes" and "Folders" items in the tree, these should not appear because they just introduce added levels of hierarchy which are not really needed.
Any other way to achieve the desire effect using only a list of Node objects?
Kind regards,
Faye
You can create a Node Layout for both the TargetTypeName = Folder and one for the TargetTypeName = Node then it will create the Nodes based underlying type od the data. Please see attached sample.
Let me know if you have any questions.