[英]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.我有一个放置了大约 4000 个对象的树视图。树视图的初始加载和填充来自对象列表,并且需要很长时间。 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.我的树视图绑定到 XAML 中的 Datacontext。
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。
<TreeView Name="MyTreeView" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" />
尝试将VirtualizingStackPanel
用于您的TreeView
,我在ComboBox
遇到了类似的问题,这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.