This is a migrated thread and some comments may be shown as answers.

TreeView Hierarchical Data Template Binding problems

2 Answers 199 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Vlad
Top achievements
Rank 1
Vlad asked on 01 Nov 2010, 09:45 AM
I am trying to databind xml nodes to hierarchical treeview. I successfully databinded to the first level of XML data source but cannot correctly databind to second and third level.  I am wondering to find out what I am doing wrong. Any similar sample will be highly appreciated. Is that possible to slide out level3 items horizontally while other levels slide out vertically? Thank you in advance.

Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<Pages xmlns="">
<page name="Name 1" UriSource="Pages/Name1.xaml" />
<page name="Name 2" UriSource="Pages/Name2.xaml" >
  
    <level2 name="ALL1" UriSource="Pages/All1.xaml" />
    <level2 name="ALL2" UriSource="Pages/All2.xaml" />
    <level2 name="ALL3" UriSource="Pages/All3.xaml" />
      
    </page>
    <page name="Name 3" UriSource="Pages/Name3.xaml"/>
        <level2 name="ALL1" UriSource="Pages/All1.xaml" >
            <level3 name="ALL3_1" UriSource="" />
            <level3 name="ALL3_2" UriSource="" />
            <level3 name="ALL3_3" UriSource="" />
        </level2 >  
              
        <level2 name="ALL2" UriSource="Pages/All2.xaml" />
        <level2 name="ALL3" UriSource="Pages/All3.xaml" />
    </page>
      
    <page name="Name 4" UriSource="Pages/Name4.xaml"/>
</Pages>

XAML:
<Window
    xmlns:telerikQuickStart="clr-namespace:Telerik.Windows.Controls.QuickStart;assembly=Telerik.Windows.Controls"
    x:Class="NavPane_2.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">
      
    <Window.Resources>
        <XmlDataProvider x:Key="PageData" Source="Data/data.xml" XPath="/Pages" />
          
        <HierarchicalDataTemplate x:Key="page" ItemsSource="{Binding XPath=page}"  ItemTemplate="{StaticResource level2}">
            <TextBlock Text="{Binding XPath=@name}" />
       </HierarchicalDataTemplate>
         
        <HierarchicalDataTemplate x:Key="level2" ItemsSource="{Binding XPath=page/level2}" ItemTemplate="{StaticResource level3}">
                <TextBlock Text="{Binding XPath=@name}" />
        </HierarchicalDataTemplate>
  
        <DataTemplate x:Key="level3" ItemsSource="{Binding XPath=page/level2/level3}">
                <TextBlock Text="{Binding XPath=@name}" />
        </DataTemplate>
  
    </Window.Resources>
  
    <Grid x:Name="LayoutRoot">
        <telerikQuickStart:HeaderedContentControl HorizontalAlignment="Center" VerticalAlignment="Center"
            Header="Sample" 
            telerikQuickStart:ThemeAwareBackgroundBehavior.IsEnabled="True"
            HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Width="250"
            Height="350">
  
            <telerik:RadTreeView 
                HorizontalAlignment="Left" Margin="8" Background="#FFF9F9F9"
                IsDragDropEnabled="True" SelectionMode="Multiple" IsSingleExpandPath="True" 
                telerik:StyleManager.Theme="Vista" 
                ItemTemplate="{StaticResource page}" 
                ItemsSource="{Binding Source={StaticResource PageData}, XPath=page}" >
        </telerik:RadTreeView>
        </telerikQuickStart:HeaderedContentControl>
    </Grid>
</Window>

2 Answers, 1 is accepted

Sort by
0
Vlad
Top achievements
Rank 1
answered on 01 Nov 2010, 04:48 PM
Any ideas? Still need help. Thank you.
0
Vlad
Top achievements
Rank 1
answered on 02 Nov 2010, 04:49 AM
I was able to achieve it based on this tutorial: http://www.telerik.com/support/kb/wpf/treeview/bind-radtreeview-in-wpf.aspx
Thank you.
Tags
TreeView
Asked by
Vlad
Top achievements
Rank 1
Answers by
Vlad
Top achievements
Rank 1
Share this question
or