Tree View won't load child items

3 posts, 1 answers
  1. jason
    jason avatar
    28 posts
    Member since:
    Oct 2010

    Posted 26 Jun 2011 Link to this post

    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}"/>
            <telerik:HierarchicalDataTemplate x:Key="WorkspaceTemplate" ItemsSource="{Binding Folders}" ItemTemplate="{StaticResource FolderItemTemplate}">
                    <TextBlock Text="{Binding Name}"/>
        <Grid x:Name="LayoutRoot" Background="White">
            <nav:RadTreeView ItemTemplate="{StaticResource WorkspaceTemplate}" IsExpandOnSingleClickEnabled="True" ItemsSource="{Binding Workspaces}" IsLoadOnDemandEnabled="True" LoadOnDemand="RadTreeView_LoadOnDemand">
  2. jason
    jason avatar
    28 posts
    Member since:
    Oct 2010

    Posted 27 Jun 2011 Link to this post

    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.
  3. Answer
    Petar Mladenov
    Petar Mladenov avatar
    3162 posts

    Posted 29 Jun 2011 Link to this post

    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.

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