Expand All extremely slow - how to show busy?

2 posts, 0 answers
  1. Bob
    Bob avatar
    63 posts
    Member since:
    Aug 2010

    Posted 08 May 2012 Link to this post


    I have a fairly simple tree, but it may contain thousands of items in 5 or 6 levels of depth.  The data collection is bound in MVVM and exists in the view model.  I created a context menu on right click that allows the user to Expand All for a single node, which could potentially open hundreds of child nodes.  When the expand command is executed, the collection is traversed and elements are changed to IsExpanded = true.

    What I notice is that my view model command executes very quickly, but then the actual tree control spends quite a long time initializing the items and displaying the levels (can be 30 seconds or longer).  I guess I can live with the long wait, but how do I present and clear a busy indicator when control is lost to the Telerik threads?  Trying to set the busy indicator around the view model command only lasts for a second.

    Are there other options for a faster or more visual response from the tree control?

    The tree:
    <HierarchicalDataTemplate x:Key="TreeObjectTemplate" ItemContainerStyle="{StaticResource containerStyle}" ItemsSource="{Binding ChildNodes}">
        <StackPanel Orientation="Horizontal">
            <TextBlock Text="{Binding DisplayName}" />
            <telerik:RadTreeView Grid.Row="0" x:Name="tvTree" ItemTemplate="{StaticResource TreeObjectTemplate}"
                            Margin="0,8,0,4" VerticalAlignment="Top" Padding="0,2,0,10"
                            IsSingleExpandPath="False" IsLineEnabled="True" ExpanderStyle="{DynamicResource ExpanderStyle}"
                            SelectionMode="Single" IsEditable="False" IsDragDropEnabled="False" ItemContainerStyle="{StaticResource containerStyle}"
                            ItemsSource="{Binding tvTreeData}"
                            SelectedItem="{Binding tvSelectedItem, Mode=TwoWay}"
                        <telerik:RadMenuItem Header="Expand All Levels" Command="{Binding ExpandCommand}"/>
                        <telerik:RadMenuItem Header="Collapse All Levels" Command="{Binding CollapseCommand}"/>
                    <i:EventTrigger EventName="PreviewUnselected">
                        <Command:EventToCommand Command="{Binding Path=PreviewUnselectedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>
                    <i:EventTrigger EventName="PreviewSelected">
                        <Command:EventToCommand Command="{Binding Path=PreviewSelectedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>

    Expand Command:
    private void ExpandAllChildren(MyTreeNode node, bool bExpandOrCollapse)
        foreach (MyTreeNode childNode in node.ChildNodes)
            ExpandAllChildren(childNode, bExpandOrCollapse);
        if (node.ChildNodes.Count > 0)
            node.IsExpanded = bExpandOrCollapse;
    private RelayCommand _expandCommand;
    public ICommand ExpandCommand
            if (_expandCommand == null)
                _expandCommand = new RelayCommand(() =>
                        UICursor = Cursors.Wait;
                        ExpandAllChildren(tvSelectedItem, true);
                        UICursor = Cursors.Arrow;
            return _expandCommand;

    Thanks for any help.  Bob C.
  2. Zarko
    Zarko avatar
    755 posts

    Posted 11 May 2012 Link to this post

    Hi Bob,
    You could try to handle the RadTreeView's ItemContainerGenerator StatusChanged event and turn off the indicator there:
    this.tvTree.ItemContainerGenerator.StatusChanged += this.OnItemContainerGeneratorStatusChanged;

    private void OnItemContainerGeneratorStatusChanged(object sender, EventArgs e)
        var generator = sender as ItemContainerGenerator;
        if (generator != null && generator.Status == GeneratorStatus.ContainersGenerated)
            this.mvm.IsBusy = false;
    Also I'd like to advise you to turn on the UI Virtualization because it will greatly improve the performance:
    <telerik:RadTreeView ...           

    If you have further questions please feel free to ask.

    Kind regards,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top