Click here to Skip to main content
16,020,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
wpf load data slow (about 100,000) a virtualization technology.Not compatible with xp. Solve expert.Each level should be 100,000.
Posted

Yes, the WPF treeview is known to be a bit slow, so don't add all the elements to the treeview.

Assuming you're using a view model, you could perform lazy initialization of the 'Children' collection for each node.

Something like:
ObservableCollection<node> children;
public ObservableCollection<node> Children
{
 get
 {
   if(children == null)
   {
     LoadChildren();
   }
   return children;
 }
}
</node></node>

where LoadChildren(); obviously must initialize and populate the children collection.

You will also need to declare a HierarchicalDataTemplate for the Node class:
<HierarchicalDataTemplate x:Key="NodeTemplate" ItemsSource="{Binding Children}">
  <StackPanel>
    <TextBlock Text="{Binding Path=Name}" />
  </StackPanel>
</HierarchicalDataTemplate>


While not a final fix for performance related to the WPF treeview, it's better than initially populating the tree with all the items. You can also expand on this method by performing the LoadChildren(); asynchronously in a separate thread.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 29-Dec-12 20:52pm    
This looks like a good work around (my 5), but it cannot make a real control for huge data, as it should be. The right idea is VirtualTreeView. Remember, there was such a thing for Delphi? Unfortunately, I never heard that anyone did such thing for Forms or WPF, even though this is quite possible. I saw one CodeProject work for Forms where the developer used available ListView as a base, which has a virtual mode. I'm reviewing it now (as I would like to have it). Unfortunately the author did not make a control class out of it.
—SA
Espen Harlinn 30-Dec-12 5:30am    
It's a work around, and it has it's limitations - but it's still far better than fully populating the treeview.

I do remember VirtualTreeView - it's blazingly fast :-D
Sergey Alexandrovich Kryukov 29-Dec-12 20:54pm    
The problem with this approach will come up as the user expands the item. Children are loaded, but not unloaded (or are they?). Anyway, a flat fragment of a tree can be too long; what to do then? No, we really need a virtual tree view...
—SA
Espen Harlinn 30-Dec-12 5:31am    
That would mean rebuilding the control from scratch - but it would be nice if somebody did just that :-D
Sergey Alexandrovich Kryukov 30-Dec-12 12:41pm    
Exactly. In a real virtual TreeView nothing is populated at all. The data can be internally cached to hold nodes to fill just the currently shown item plus some up and down...
—SA
Thank you.Is the window Xp above is not compatible delay to load data.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-May-14 2:39am    
This is not an answer. Such posts are considered as abuse. And no one gets notification on such posts. Please use comments and/or "Improve question" instead.
—SA
Is there no corresponding source code, though I refer to this problem has troubled days.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900