简体   繁体   中英

TreeView optimization with large amount of data

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.

尝试将虚拟化添加到您的 TreeView。

<TreeView Name="MyTreeView" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" />

尝试将VirtualizingStackPanel用于您的TreeView ,我在ComboBox遇到了类似的问题,这解决了我的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM