by
0
7
2,345
2
Top 1% !
Popular
Famous
Easy-to-find
Specified
Refined
OpenSource
Popularity: 7692nd place

Published on:

InputName0parent
InputType0FrameworkElement
LanguageCSharp
LicenseMIT_X11
MethodNameGetLogicalChildrenBreadthFirst
OSWindows
OutputTypeIEnumerable<FrameworkElement>

GetLogicalChildrenBreadthFirst: 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 namescop...

<summary>
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.
</summary>
<param name="parent">The parent framework element.</param>
<returns>The logical children of the framework element.</returns>
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/287045/GetLogicalChildrenBreadthFirst--Retrieve?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Windows; using System.Windows.Media; /// <summary> /// 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. /// </summary> /// <param name="parent">The parent framework element.</param> /// <returns>The logical children of the framework element.</returns> public 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); } } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus