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

Tree View won't load child items

2 Answers 60 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
jason
Top achievements
Rank 1
jason asked on 27 Jun 2011, 12:01 AM
I am trying to write the treeview control using LoadOnDemand and HierarchialDataTemplates.  The parent nodes load fine but then when I click on one the loading circle runs and nothing else happens.  I have stepped through the code and Folders (an ObservableCollection<FolderNode>) does have data so not sure what is wrong.  here is my xaml:

<UserControl.Resources >
        <DataTemplate x:Key="FolderItemTemplate">
            <TextBlock Text="{Binding FolderName}"/>
        </DataTemplate>
 
        <telerik:HierarchicalDataTemplate x:Key="WorkspaceTemplate" ItemsSource="{Binding Folders}" ItemTemplate="{StaticResource FolderItemTemplate}">
                <TextBlock Text="{Binding Name}"/>
        </telerik:HierarchicalDataTemplate>
    </UserControl.Resources>
 
    <Grid x:Name="LayoutRoot" Background="White">
        <nav:RadTreeView ItemTemplate="{StaticResource WorkspaceTemplate}" IsExpandOnSingleClickEnabled="True" ItemsSource="{Binding Workspaces}" IsLoadOnDemandEnabled="True" LoadOnDemand="RadTreeView_LoadOnDemand">
            
            
        </nav:RadTreeView>
    </Grid>

2 Answers, 1 is accepted

Sort by
0
jason
Top achievements
Rank 1
answered on 27 Jun 2011, 02:25 PM
I have gotten beyond my original problem now as I did not realize that 'Folders' had to be an IEnumerable inside Workspaces.  My problem now is that I have this hierarchy:  Workspaces --> Folders.  Folders will not have any child items in the tree because when you click on a folder it will load the document list into a grid.  My problem is that after I expand a workspace then folders can also be expanded.  How can I make it so Folders is the bottom level?  I thought my hierarchialdatatemplate referencing just a DataTemplate would take care of that but apparently not.
0
Accepted
Petar Mladenov
Telerik team
answered on 29 Jun 2011, 04:59 PM
Hello jason,

There are two basic approaches to handle this. The first is "code-behind" solution and it uses the ItemPrepared event of the RadTreeView - it fires every time a container ( RadTreeViewItem is prepared). In your case you will have to do something like;
if( e.PreparedItem.Item is Folder)
     e.Prepareditem.IsLoadOnDemandEnabled = false;
The second approach should be used if you use ViewModels to wrap your business objects (or objects from a DB). You can expose a boolean property in your FolderViewModel and bind it to the IsLoadOnDemandEnabled property of the RadTreeViewItem via ContainerBindings.
Please let us know if this helped you.

Greetings,
Petar Mladenov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
jason
Top achievements
Rank 1
Answers by
jason
Top achievements
Rank 1
Petar Mladenov
Telerik team
Share this question
or