I'm sure there is a better way of doing this but I just want to know why this isn't working. While debugging, the debugger skips over GetAllChildren(
public static IEnumerable<DependencyObject> GetAllChildren(DependencyObject d)
{
if (d.GetType().GetProperties().Any(p => p.Name == "Content"))
{
var v = (DependencyObject)(d.GetType().GetProperty("Content").GetValue(d));
GetAllChildren(v);
yield return v;
}
if (d.GetType().GetProperties().Any(p => p.Name == "Children"))
{
foreach (DependencyObject v in (UIElementCollection)d.GetType().GetProperty("Children").GetValue(d))
{
yield return v;
GetAllChildren(v);
}
}
}