Пример #1
0
        /// <summary>
        /// Traverses from this node to each successive parent until a node with parent is reached.
        /// </summary>
        /// <param name="func"></param>
        public void TraverseToTop(HierarchicalViewModelAction func)
        {
            HierarchicalViewModelBase p = this;

            while (p != null)
            {
                func(p);
                p = p.Parent;
            }
        }
Пример #2
0
        /// <summary>
        /// Visits this node, and all children recursively (i.e. It traverses the tree 'downwards' only, from parent to child).
        /// </summary>
        /// <param name="action"></param>
        public void Traverse(HierarchicalViewModelAction action)
        {
            if (action == null)
            {
                return;
            }

            // Firstly visit me...
            action(this);
            // then each of my children
            foreach (HierarchicalViewModelBase child in Children)
            {
                child.Traverse(action);
            }
        }