Hello,
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:
Expand Command:
Thanks for any help. Bob C.
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}" /> </StackPanel></HierarchicalDataTemplate> <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}" MouseRightButtonDown="treeView_MouseRightButtonDown"> <telerik:RadContextMenu.ContextMenu> <telerik:RadContextMenu> <telerik:RadMenuItem Header="Expand All Levels" Command="{Binding ExpandCommand}"/> <telerik:RadMenuItem Header="Collapse All Levels" Command="{Binding CollapseCommand}"/> </telerik:RadContextMenu> </telerik:RadContextMenu.ContextMenu> <i:Interaction.Triggers> <i:EventTrigger EventName="PreviewUnselected"> <Command:EventToCommand Command="{Binding Path=PreviewUnselectedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/> </i:EventTrigger> <i:EventTrigger EventName="PreviewSelected"> <Command:EventToCommand Command="{Binding Path=PreviewSelectedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/> </i:EventTrigger> </i:Interaction.Triggers> </telerik:RadTreeView>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{ get { if (_expandCommand == null) { _expandCommand = new RelayCommand(() => { try { UICursor = Cursors.Wait; ExpandAllChildren(tvSelectedItem, true); } catch { } finally { UICursor = Cursors.Arrow; } }); } return _expandCommand; }}Thanks for any help. Bob C.