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

RadTreeView only showing root nodes

1 Answer 60 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 17 Jul 2013, 06:59 PM
I have a Silverlight 5 project that needs to use a RadTreeView, currently installed version 2012.2.912.1050
Below is my code, and it's about as simple as I could possibly make it, as far as I know.
My page should show a bound 'Title' component, a separater line, and then the RadTreeView (RTV).

I have a collection called ClientAssets, which is a hierarchical representation of my data, as an ObservableCollection<ClientAsset>.  When that collection has been populated in the Setter I also do an OnPropertyChanged.  My RTV's itemsource is this collection, and I have my HierarchicalDataTemplate that is bound to my Children collection.  Each object has a bunch of other properties, but all I really care about in this example is showing the bound property AssetName, and the Children collection for the tree. 

With what I have below (minus the Grid formatting code which has been removed), all I see are the 2 root nodes (which is correct for my test data), with one of them having the expand triangle (it has children).  When I expand this item, I see only the space where the two children should reside, but there's nothing there.  What am I missing or doing wrong with my setup?

Initially, I thought my collection might be wrong in some way but when I create my own data I get the same thing: Only root nodes with empty space where the children should reside.  I have another more complicated example of the RadTreeView in this project, and that works just fine.  What am I doing wrong?

Thanks!

<UserControl.Resources>
        
            <telerik:HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource="{Binding Children}">
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">                                      
                <TextBlock Text="{Binding AssetName}" Style="{StaticResource Normal}"/>               
            </StackPanel>
        </telerik:HierarchicalDataTemplate>         
    </UserControl.Resources>
    
        <StackPanel Orientation="Vertical" Grid.Row="0">
            <ContentControl Content="{Binding Title}" HorizontalContentAlignment="Stretch" />
            <Line X1="5" X2="10" Y1="0" Y2="0" Stroke="Gray" StrokeThickness="1" Width="Auto" Stretch="Fill" />      
            <telerikNav:RadTreeView HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5,10,0,5"
                ItemsSource="{Binding ClientAssets}" x:Name="rtvCA"               
                ItemTemplate="{StaticResource NodeTemplate}">               
                <telerikNav:RadTreeView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel VerticalAlignment="Top" Orientation="Vertical"/>                       
                    </ItemsPanelTemplate>
                </telerikNav:RadTreeView.ItemsPanel>
            </telerikNav:RadTreeView>
        </StackPanel>
        
    </Grid>

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 17 Jul 2013, 10:22 PM
I need a RadTreeViewItem style!

Seems that I was only getting root nodes because they use the ItemTemplate that existed on the xaml.  All children require the ItemContainerStyle to provide instruction for how to display those elements.  I bound my ItemContainerStyle to AssetTreeViewItemStyle (shown below) and I can now see my other items.  You need both the ItemsPanel, and the ItemContainerStyle for your data to appear.

Woo Hoo!
<Style x:Key="AssetTreeViewItemStyle" TargetType="telerikNavigation:RadTreeViewItem">
       <Setter Property="TextOptions.TextHintingMode" Value="Fixed" />
       <Setter Property="ItemsPanel">
           <Setter.Value>
               <ItemsPanelTemplate>
                   <StackPanel Margin="4,6"
                               HorizontalAlignment="Left"
                               Orientation="Vertical" />
               </ItemsPanelTemplate>
           </Setter.Value>
       </Setter>
       <Setter Property="ItemContainerStyle">
           <Setter.Value>
               <Style TargetType="telerikNavigation:RadTreeViewItem">
                   <Setter Property="ItemsPanel">
                       <Setter.Value>
                           <ItemsPanelTemplate>
                               <StackPanel Margin="2,2"
                                           HorizontalAlignment="Left"
                                           Orientation="Vertical" />
                           </ItemsPanelTemplate>
                       </Setter.Value>
                   </Setter>
               </Style>
           </Setter.Value>
       </Setter>
   </Style>
Tags
TreeView
Asked by
Richard
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or