[WPF] Extreme slowdown when databinding

I have been working on a small app, and have bound a Treeview to a data object, but when I'm in the app and open the node that is bound, it takes a very long time to load. It is a large node (7100 items) but it takes ~50 seconds to load. Is that a product of the size, or is it possible that I am doing things wrong causing the slowdown? Here is some of my code:

Datacontext set in main window constructor:

public MainWindow() { InitializeComponent(); CQSystemList systems = (CQSystemList)CQSystemList.Load(sysall); base.DataContext = systems; } 

XAML Binding

<TreeViewItem x:Name="treeViewAll" Header="All Systems" AllowDrop="True" ItemsSource="{Binding Path=.}"> <TreeViewItem.ItemTemplate> <DataTemplate> <TreeViewItem Header="{Binding _sysName}"/> </DataTemplate> </TreeViewItem.ItemTemplate> </TreeViewItem> 

Part of my class code. I was worried that maybe I was creating a new list each time, but I only call the Load() method once at startup, so I don't think that's the case. Included the code nonetheless.

public class CQSystemList : ObservableCollection<CQSystem> { public static ObservableCollection<CQSystem> Load(string sysAll) { CQSystemList tempList = new CQSystemList(); while(reader.Read()) { CQSystem _sys = new CQSystem((int)reader[0],(string)reader[4],(string)reader[5],(string)reader[6]); tempList.Add(_sys); } List<CQSystem> list = new List<CQSystem>(); list = tempList.ToList<CQSystem>(); list = list.DistinctBy(x => x._sysName).ToList(); CQSystemList sysList = new CQSystemList(); for (int i = 0; i < list.Count();i++ ) { sysList.Add(list[i]); } return sysList; } } 

by Fun_Hat via /r/csharp

Leave a Reply