private static void SetChildParentReferences(int parentIndex, List <TreeViewItem> visibleItems) { TreeViewItem treeViewItem = visibleItems[parentIndex]; bool flag = treeViewItem.children != null && treeViewItem.children.Count > 0 && treeViewItem.children[0] != null; if (flag) { return; } int depth = treeViewItem.depth; int num = 0; for (int i = parentIndex + 1; i < visibleItems.Count; i++) { if (visibleItems[i].depth == depth + 1) { num++; } if (visibleItems[i].depth <= depth) { break; } } List <TreeViewItem> list = null; if (num != 0) { list = new List <TreeViewItem>(num); num = 0; for (int j = parentIndex + 1; j < visibleItems.Count; j++) { if (visibleItems[j].depth == depth + 1) { visibleItems[j].parent = treeViewItem; list.Add(visibleItems[j]); num++; } if (visibleItems[j].depth <= depth) { break; } } } TreeViewUtility.SetChildren(treeViewItem, list); }
private static void SetChildParentReferences(int parentIndex, List <TreeViewItem> visibleItems) { TreeViewItem visibleItem = visibleItems[parentIndex]; if (visibleItem.children != null && visibleItem.children.Count > 0 && visibleItem.children[0] != null) { return; } int depth = visibleItem.depth; int capacity = 0; for (int index = parentIndex + 1; index < visibleItems.Count; ++index) { if (visibleItems[index].depth == depth + 1) { ++capacity; } if (visibleItems[index].depth <= depth) { break; } } List <TreeViewItem> newChildList = (List <TreeViewItem>)null; if (capacity != 0) { newChildList = new List <TreeViewItem>(capacity); int num = 0; for (int index = parentIndex + 1; index < visibleItems.Count; ++index) { if (visibleItems[index].depth == depth + 1) { visibleItems[index].parent = visibleItem; newChildList.Add(visibleItems[index]); ++num; } if (visibleItems[index].depth <= depth) { break; } } } TreeViewUtility.SetChildren(visibleItem, newChildList); }