Lets take the example of a file system where you have something such as:
<Folder folderName="c:\">
<File fileName="somefile.txt" />
<Folder folderName="windows" />
</Folder>
I intentionally named them folderName and fileName to differentiate in the xaml example if this is possible. Some of the examples name almost everything "Title" or "Name" etc so it is hard to differentiate.
Is this possible? btw.. this would include using a specific file icon and folder icon. I know via code I can enumerate and add items, but im wondering if binding is possible via one xml datasource.
thanks!
Hi adamtuliper,
In order to achieve presenting this data in XamWebTree, you will have to read the XML and create an IEnumerable (e.g. ObservableCollection) of data objects, then bind the XamWebTree to this IEnumerable by setting the ItemsSource property and finally provide a Template for the automatically generated by the data binding XamWebTreeItems.
You will have to use the HierarchicalItemTemplate property of the XamWebTree and XamWebTreeItem and HierarchicalDataTemplate class in Infragistics.Silverlight.
See this post for more info.
In the data objects of your resulting from the XML IEnumerable, you will have to put either the "fileName" or "folderName" in a single property, e.g. "Name" and also, you will have to have an icon properties like e.g. ExpandedIcon and CollapsedIcon. For example:
public class MyDataFromXML { public string Name { get; set; } public BitmapImage CollapsedIcon { get; set; } public BitmapImage ExpandedIcon { get; set; } public ObservableCollection<MyDataFromXML> Children { get; set; } }
Your HierarchicalDataTemplate would be something like:
<ig:HierarchicalDataTemplate ItemsSource="{Binding Children}"> <DataTemplate> <TextBlock Text="{Binding Name}" /> </DataTemplate> <ig:HierarchicalDataTemplate.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Name}" /> </DataTemplate> </ig:HierarchicalDataTemplate.ItemTemplate> <ig:HierarchicalDataTemplate.DefaultItemsContainer> <DataTemplate> <igTree:XamWebTreeItem CollapsedIcon="{Binding CollapsedIcon}" ExpandedIcon="{Binding ExpandedIcon}"/> </DataTemplate> </ig:HierarchicalDataTemplate.DefaultItemsContainer> </ig:HierarchicalDataTemplate>
Please, let us know if you have more questions.
HTH,
thanks for the reply. It is still a bit off.. using that template with this data:
<?xml version="1.0" encoding="utf-8" ?><fileSystem> <folder name="c:\"> <file name="file1.txt" /> <file name="file2.txt" /> <folder name="windows"> <file name="sub item 1" /> <file name="sub item 2" /> <file name="sub item 3" /> <file name="sub item 4" /> </folder> </folder>
<folder name="d:\"> <file name="file10.txt" /> <file name="file11.txt" /> <file name="file12.txt" /> <folder name="program files"> <file name="program1" /> <file name="program2" /> </folder> </folder></fileSystem>
I receive a tree that looks like: (note items with * are incorrect)
c:\ file1.txt file2.txt sub item 1 (*) sub item 2 (*) sub item 3 (*) sub item 4 (*)windows sub items 1-4d:\ file10.txt file11.txt file12.txt program1 (*) program2 (*)
program files program1 program2
so it folds up the subfolders into the current folder IE doesnt show the folder windows under c:\