/// <summary> /// Expands or unexpands a specific node /// </summary> /// <param name="node"></param> /// <param name="expand"></param> public void ExpandNode(TaskTreeNode node, bool expand) { if (expand != node.isExpanded) { int index = stackPanel.Children.IndexOf(node); if (expand) { node.isExpanded = true; try { foreach (TaskTreeNode n in node.children) { stackPanel.Children.Insert(index + 1, n); InitalizeExpandNode(n); index += GetVisibleChildCount(n) + 1; } } catch (Exception ex) { Console.WriteLine(ex); RefreshAll(); return; } } else { int children = GetVisibleChildCount(node); try { stackPanel.Children.RemoveRange(index + 1, children); } catch (Exception ex) { Console.WriteLine(ex); RefreshAll(); return; } node.isExpanded = false; } node.ExpanderRefresh(); } }
private void NodeAddToTree(TaskTreeNode node) { stackPanel.Children.Add(node); nodeDictionary[node.ID] = node; AddEvents(node); foreach (TaskTreeNode n in node.children) { NodeAddToTree(n); } }
/// <summary> /// Puts a certain node into focus /// </summary> /// <param name="node"></param> public void Select(TaskTreeNode node) { foreach (TaskTreeNode n in selectedNodes) { n.Deselect(); } selectedNodes.Clear(); selectedNodes.Add(node); node.Select(); OnSelectionChanged(); }
public void AddNode(Task task, string parentID, bool expandParent) { TaskTreeNode parentNode = nodeDictionary[parentID]; TaskTreeNode node = new TaskTreeNode(task, parentNode.depth + 1); if (expandParent) { ExpandNode(parentNode, true); } parentNode.children.Add(node); parentNode.ExpanderRefresh(); NodeAddToTree(node, parentNode); }
private void NodeAddToTree(TaskTreeNode node, TaskTreeNode parentNode) { if (stackPanel.Children.Contains(parentNode)) //Only add to panel if the parent is visible { int index = stackPanel.Children.IndexOf(parentNode) + GetVisibleChildCount(parentNode); stackPanel.Children.Insert(index, node); } nodeDictionary[node.ID] = node; AddEvents(node); foreach (TaskTreeNode n in node.children) { NodeAddToTree(n, node); } }
private int GetVisibleChildCount(TaskTreeNode node) { int count = 0; if (node.isExpanded) { count += node.children.Count; foreach (TaskTreeNode n in node.children) { count += GetVisibleChildCount(n); } } return(count); }
/// <summary> /// Creates the subnodes for a node assuming they were not there before /// </summary> /// <param name="node"></param> private void InitalizeExpandNode(TaskTreeNode node) { if (node.isExpanded) { int index = stackPanel.Children.IndexOf(node); foreach (TaskTreeNode n in node.children) { stackPanel.Children.Insert(index + 1, n); InitalizeExpandNode(n); index += GetVisibleChildCount(n) + 1; } } node.ExpanderRefresh(); }
public void RemoveNode(List <TaskTreeNode> nodes, string nodeID) { for (int i = 0; i < nodes.Count; i++) { TaskTreeNode n = nodes[i]; if (n.ID == nodeID) { nodes.Remove(n); i--; } else { RemoveNode(n.children, nodeID); } } }
public void AddNode(Task task) { TaskTreeNode node = new TaskTreeNode(task, 0); NodeAddToTree(node); }
private void Node_ExpandUpdated(object sender, ExpandUpdatedEventArgs e) { TaskTreeNode node = (TaskTreeNode)sender; ExpandNode(node, e.expanded); }
private void AddEvents(TaskTreeNode node) { node.SelectionChanged += Node_SelectionChanged; node.ExpandUpdated += Node_ExpandUpdated; }