You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1004 B
38 lines
1004 B
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<DependencyObject>(); |
|
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; |
|
} |
|
} |
|
}
|
|
|