System.Windows.Controls.VisualTreeExtensions.GetLogicalChildrenBreadthFirst C# (CSharp) Méthode

GetLogicalChildrenBreadthFirst() static private méthode

Retrieves all the logical children of a framework element using a breadth-first search. A visual element is assumed to be a logical child of another visual element if they are in the same namescope. For performance reasons this method manually manages the queue instead of using recursion.
static private GetLogicalChildrenBreadthFirst ( this parent ) : IEnumerable
parent this The parent framework element.
Résultat IEnumerable
        internal static IEnumerable<FrameworkElement> GetLogicalChildrenBreadthFirst(this FrameworkElement parent)
        {
            Debug.Assert(parent != null, "The parent cannot be null.");

            Queue<FrameworkElement> queue =
                new Queue<FrameworkElement>(parent.GetVisualChildren().OfType<FrameworkElement>());

            while(queue.Count > 0)
            {
                FrameworkElement element = queue.Dequeue();
                yield return element;

                foreach(FrameworkElement visualChild in element.GetVisualChildren().OfType<FrameworkElement>())
                {
                    queue.Enqueue(visualChild);
                }
            }
        }
    }