public bool ChangePosition <T>(ObservableList <TreeNode <T> > nodes, Predicate <TreeNode <T> > match, int position) { var findedNode = nodes.Find(match); if (findedNode != null) { nodes.BeginUpdate(); nodes.Remove(findedNode); nodes.Insert(position, findedNode); nodes.EndUpdate(); return(true); } foreach (var node in nodes) { if (node.Nodes == null) { continue; } if (ChangePosition(node.Nodes as ObservableList <TreeNode <T> >, match, position)) { return(true); } } return(false); }
/// <summary> /// Remove node if it's match specified function. /// </summary> /// <typeparam name="T">Node type.</typeparam> /// <param name="nodes">Nodes.</param> /// <param name="match">Match function.</param> /// <returns>true if node removed; otherwise, false.</returns> public static bool Remove <T>(ObservableList <TreeNode <T> > nodes, Predicate <TreeNode <T> > match) { var findedNode = nodes.Find(match); if (findedNode != null) { findedNode.Parent = null; // this.nodes.Add(findedNode as TreeNode<TreeViewItem>); return(true); } foreach (var node in nodes) { if (node.Nodes == null) { continue; } if (Remove(node.Nodes, match)) { return(true); } } return(false); }
public T Find(Func <T, bool> condition) { return(_list.Find(condition)); }
/// <summary> /// Finds child named childWord. If not found, returns null. /// </summary> /// <param name="childWord">Word to find</param> /// <returns>Found node</returns> public WordMapNode FindChild(string childWord) { WordMapNode foundNode = Next.Find(x => x.Word == childWord); return(foundNode); }