Esempio n. 1
0
        /// <summary>
        /// Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the specified nodes.
        /// </summary>
        /// <param name="searchNodes">Nodes to search.</param>
        /// <param name="match">The Predicate{TItem} delegate that defines the conditions of the element to search for.</param>
        /// <returns>The first element that matches the conditions defined by the specified predicate, if found; otherwise, null.</returns>
        protected static TreeNode <TItem> FindNode(ObservableList <TreeNode <TItem> > searchNodes, Predicate <TreeNode <TItem> > match)
        {
            if (searchNodes == null)
            {
                return(null);
            }

            var result = searchNodes.Find(match);

            if (result != null)
            {
                return(result);
            }

            foreach (var node in searchNodes)
            {
                var subnode = FindNode(node.Nodes, match);

                if (subnode != null)
                {
                    return(subnode);
                }
            }

            return(null);
        }