using System.Collections.Generic; using System.Windows; using System.Windows.Media; namespace Kingo.Plugin.NYYP { static class VisualTreeModule { public static FrameworkElement FindChild(DependencyObject obj, string childName) { if (obj == null) return null; var queue = new Queue(); queue.Enqueue(obj); while (queue.Count > 0) { obj = queue.Dequeue(); var childCount = VisualTreeHelper.GetChildrenCount(obj); for (var i = 0; i < childCount; i++) { var child = VisualTreeHelper.GetChild(obj, i); var fe = child as FrameworkElement; if (fe != null && fe.Name == childName) { return fe; } queue.Enqueue(child); } } return null; } } }