/// <summary> /// Adds an item to the tree. /// </summary> protected virtual TreeItemViewModel AddNode(TreeItemViewModel parent, object item, string text, string icon) { // create node. TreeItemViewModel treeNode = new TreeItemViewModel(NodesTV, parent); // update text/icon. UpdateNode(treeNode, item, text, icon); // add to control. if (parent == null) { NodesTV.TreeItems?.Add(treeNode); } else { parent.Children.Add(treeNode); } // return new tree node. return(treeNode); }
/// <summary> /// Updates a tree node with the current contents of an object. /// </summary> protected virtual void UpdateNode(TreeItemViewModel treeNode, object item, string text, string icon) { treeNode.Text = text; treeNode.Item = item; treeNode.Icon = icon; switch (icon) { case "Server": treeNode.Brush = new SolidColorBrush(Colors.Green); break; case "ServerStopped": treeNode.Brush = new SolidColorBrush(Colors.Red); break; case "ServerKeepAliveStopped": treeNode.Brush = new SolidColorBrush(Colors.Yellow); break; default: treeNode.Brush = null; break; } }
/// <summary> /// Initializes a node before expanding it. /// </summary> protected virtual Task BeforeExpand(TreeItemViewModel clickedNode) { return(Task.CompletedTask); }
/// <summary> /// Enables the state of menu items. /// </summary> protected virtual void EnableMenuItems(TreeItemViewModel clickedNode) { // do nothing. }
/// <summary> /// Returns the data to drag. /// </summary> protected virtual object GetDataToDrag(TreeItemViewModel node) { return(node.Item); }
/// <summary> /// Adds an item to the tree. /// </summary> protected virtual TreeItemViewModel AddNode(TreeItemViewModel treeNode, object item) { return(AddNode(treeNode, item, String.Format("{0}", item), "ClosedFolder")); }