public static IEnumerable <T> GetDescendants <T>(
            ITreeTraversalStrategy strategy,
            DependencyObject root,
            Func <T, bool> predicate,
            Func <DependencyObject, bool> expand) where T : class
        {
            if (strategy == null)
            {
                throw new ArgumentNullException("strategy");
            }

            if (root == null)
            {
                yield break;
            }

            var traversal = strategy.Create();

            Debug.Assert(traversal != null);

            traversal.VisitNodes(TreeHelper.GetChildren(root));

            while (traversal.MoveNext())
            {
                var current    = traversal.Current;
                var descendant = current as T;

                if ((descendant != null) && ((predicate == null) || predicate.Invoke(descendant)))
                {
                    yield return(descendant);
                }

                if ((expand == null) || expand.Invoke(current))
                {
                    traversal.VisitNodes(TreeHelper.GetChildren(current));
                }
            }
        }
 public static IEnumerable <T> GetDescendants <T>(ITreeTraversalStrategy strategy, DependencyObject root, Func <T, bool> predicate) where T : class
 {
     return(TreeHelper.GetDescendants <T>(strategy, root, predicate, null));
 }
 public static IEnumerable <T> GetDescendants <T>(ITreeTraversalStrategy strategy, DependencyObject root) where T : DependencyObject
 {
     return(TreeHelper.GetDescendants <T>(strategy, root, null, null));
 }