Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Binding to n-levels
posted

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!

Parents
No Data
Reply
  • 5595
    Suggested Answer
    posted

    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,

Children