Hi,
I have the following structure:
Folder
{
string Name;
List<Node> childFolders;
List<Element> childFiles;
};
File
int size;
etc...
A tree node can be either a Folder element or a File element. When displaying a folder, I only need to display the name, but when displaying a file, I need to display all data in the File structure in a datagrid.
I have tried setting the following GlobalNodeLayouts:
<ig:XamDataTree x:Name="MyTree" ItemsSource="{Binding MyData}"> <ig:XamDataTree.GlobalNodeLayouts> <ig:NodeLayout Key="Folders" TargetTypeName="Folder" DisplayMemberPath="Name"> </ig:NodeLayout>
<ig:NodeLayout Key="Files" TargetTypeName="File" DisplayMemberPath="Name"> <ig:NodeLayout.ItemTemplate> <DataTemplate> <Grid> <igDP:XamDataGrid> </igDP:XamDataGrid> </Grid> </DataTemplate> </ig:NodeLayout.ItemTemplate> </ig:NodeLayout> </ig:XamDataTree.NodeLayouts></ig:XamDataTree>
but with this structure I get the File layouts even when I have no Files in the folder. Also, I am having trouble binding to the datagrid. Can you let me know the correct syntax for binding to the datagrid?
I would like to display files when they are present and folders when folders are present.
Thanks
i have goine through the sample its worked for me but now i want to display different icons/images(for every type of node having different icon) for different types of nodes so how can i do that?
Yashwant Mahajan
HI,
I have tried to implement something similar to your sample in my code. One thing i found is, when the object is of Folder type, then in the visibilty of the fileTextBlock as well as (to display folders) and the Grid to display the file information, both the controls are visible. Which not the case when we bind it to a File type. I would like that, incase of Folder type, visibilty of the grid which displays file information should be collapsed.I am not able to figure out the reason for this. Can you help me to resolve this?
Refards,
sachin
Hi Konstantin,
Thanks for your help. I was able to implement what I needed with the help of the sample project you posted.
Regards,
Hello gvsecmbh,
When your target type exposes more than one property of collection of recognized types it creates a sub-node for each property(its text comes from the key property of the applied node layout). These sub-nodes are always displayed no mater if they have any elements or not.
You could achieve your scenario by defining an interface(lets call it Node) which Folder and File classes implement. Then you can expose a collection of type Node. Finally you should provide a suitable DataTemplate for the Layout with TargetType="Node".
Here is sample solution illustrating the approach described above.
About your trouble with the binding in the ItemTemplate - tha DataContext for NodeLayout is if type XamDataTreeNodeDataContext. It exposes two properties Data and Node. So your binding should looks like this {Binding Path=Data.Name}.
HTH