RadTreeView IsVirtualizing not rendering all tree nodes

3 posts, 1 answers
  1. Sergio
    Sergio avatar
    2 posts
    Member since:
    Feb 2014

    Posted 02 Apr 2015 Link to this post

    I'm having an issue when I expand a node with many children only the first 20 or so out of 1500 are rendered on screen.

    XAML CODE

    <UserControl.Resources>
            <telerik:HierarchicalDataTemplate x:Key="ItemTemplate" ItemsSource="{Binding Children}">
                <StackPanel Orientation="Horizontal">               
                    <TextBlock Text="{Binding Node}" Foreground="Black" FontWeight="Bold" FontSize="15" />
                </StackPanel>
            </telerik:HierarchicalDataTemplate>
        </UserControl.Resources>
    ...

    <telerik:RadTreeView x:Name="RadTreeViewTest" Margin="5" IsVirtualizing="True" MaxHeight="300"
                                 ItemsSource="{Binding}"
                                 IsExpandOnSingleClickEnabled="True"
                                 IsExpandOnDblClickEnabled="False"
                                 ItemTemplate="{StaticResource ItemTemplate}"
                                 IsLoadOnDemandEnabled="True"
                                 LoadOnDemand="RadTreeViewItem_OnLoadOnDemand">        
            </telerik:RadTreeView>


    Codebehind for the ondemand fetch

    private void RadTreeViewItem_OnLoadOnDemand(object sender, RadRoutedEventArgs e)
            {
                RadTreeViewItem clickedItem = e.OriginalSource as RadTreeViewItem;
                VirtualTreeItem item = clickedItem.Item as VirtualTreeItem;

                for (int i = 0; i < 1500; i++)
                {
                    item.Children.Add(new VirtualTreeItem(i.ToString(), ("Item" + i), i.ToString(),item));
                }

                clickedItem.IsExpanded = true;
                clickedItem.BringIntoView();
                clickedItem.IsLoadOnDemandEnabled = false;
            }



    Any idea why all my items aren't rendering or how to fix it?








  2. Sergio
    Sergio avatar
    2 posts
    Member since:
    Feb 2014

    Posted 02 Apr 2015 in reply to Sergio Link to this post

    Just noticed that if I reload the RadTreeView again with all the items already in memory from the previous onDemand calls the virtualization works perfectly fine. Do I need to do something for the tree to update correctly with onDemand so virtualization will recognize all the items?
  3. DevCraft banner
  4. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 06 Apr 2015 Link to this post

    Hello Sergio,

    As discussed privately, changing  the root and child collection types from Lists to ObservableCollections will resolve this scenario. Please let us know if this works correctly on your side.

    Regards,
    Petar Mladenov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top