TreeView Hierarchical Data Template Binding problems

3 posts, 0 answers
  1. Vlad
    Vlad avatar
    19 posts
    Member since:
    Nov 2010

    Posted 01 Nov 2010 Link to this post

    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. Vlad
    Vlad avatar
    19 posts
    Member since:
    Nov 2010

    Posted 01 Nov 2010 Link to this post

    Any ideas? Still need help. Thank you.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Vlad
    Vlad avatar
    19 posts
    Member since:
    Nov 2010

    Posted 01 Nov 2010 Link to this post

    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.
Back to Top