I have a treeview that I put ~4000 objects in. The initial load and fill of my treeview comes from a list of objects, and it takes a LONG time. This is how I fill it :
private List<ItemIdPair> m_itemList;
public List<ItemIdPair> ItemList {
get { return m_itemList; }
set { m_itemList = value; }
}
public void Window_Loaded(object sender, RoutedEventArgs e) {
try {
ItemList = ItemListParse(); // data from .txt file (NOT the performance problem)
ItemList = ItemList.OrderBy(o => o.ItemName).ToList();
ItemTreeView.DataContext = ItemList;
} catch(Exception ex) { }
}
My treeview is bound to my Datacontext in the XAML.
I also have a textbox to search the treeview and narrow the results which ALSO has a huge performance hit. It looks like this :
public void LoadTree(string search) {
try {
List<ItemIdPair> items = ItemList.Where(i => i.ItemName.ToLower().Contains(search.ToLower())).ToList();
ItemTreeView.DataContext = items;
} catch(Exception ex) { }
}
any tips on how I can optimize this, or refactor it to give me a performance boost? There's no way that a Treeview should behave this slow.
Try adding Virtualization to your TreeView.
<TreeView Name="MyTreeView" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With