Articles in this section
Category / Section

How to populate a WPF TreeViewAdv by using XML data with Bulletin support?

2 mins read

This article describes how to populate a WPF TreeViewAdv control by using Extensible Markup Language data. As both XML and TreeViewAdv control represents the data in a hierarchical format, xml source is binded to TreeViewAdv using XmlDataProvider. Follow the below steps to populate TreeViewAdv control using xml file

Step 1: Create the XML file.

<Products>
  <Product Name="Tools">
      <Feature Name="Ribbon">
           <Feature Name="Office2010UI"/>
           <Feature Name="Data Binding Support"/>
      </Feature>
      <Feature Name="Docking Manager">
            <Feature Name="Maximization"/>
            <Feature Name="State Persistence"/>
      </Feature>
      <Feature Name="TreeView"> 
            <Feature Name="Editing"/>
            <Feature Name="Sorting"/>
       </Feature>
  </Product>
</Products>

Step 2: Add the XmlDataProvider for the above XML file as follows

<XmlDataProvider Source="Data.xml" 
                 x:Key="xmlSource" 
                 XPath="Products"/>

Step 3: Set the ItemSource property for the TreeViewAdv as follows

<syncfusion:TreeViewAdv  ShowRootLines="False"                
                         ItemsSource="{Binding Source={StaticResource xmlSource}, XPath=Product}" >
     <syncfusion:TreeViewAdv.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding XPath=Feature}">
             <StackPanel Orientation="Horizontal">
                 <Image Height="15" 
                        Source="Bullet.png"  
                        Visibility="Visible"/>
                 <TextBlock Margin="10" 
                            Text="{Binding XPath=@Name}" />
             </StackPanel>
        </HierarchicalDataTemplate>
     </syncfusion:TreeViewAdv.ItemTemplate>
  </syncfusion:TreeViewAdv>

The above code generate the following output


D:\My KB\Vol13.4\Sprint4\Images\sshot-5.png

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied