I have tried finding an answer to this problem and in every post I find there is an answer to finding children recursively but none of them work with hidden or collapsed children
Also in every post someone has asked if this is possible but no one has answered so I am beginning to think this isn't possible
If anyone has a way of doing this I will be eternally grateful.
My function looks like this:
public static DependencyObject FindLogicalDescendentByName(this DependencyObject source, string name)
{
DependencyObject result = null;
IEnumerable children = LogicalTreeHelper.GetChildren(source);
foreach (var child in children)
{
if (child is DependencyObject)
{
if (child is FrameworkElement)
{
if ((child as FrameworkElement).Name.Equals(name))
result = (DependencyObject)child;
else
result = (child as DependencyObject).FindLogicalDescendentByName(name);
}
else
{
result = (child as DependencyObject).FindLogicalDescendentByName(name);
}
if (result != null)
return result;
}
}
return result;
}
-EDITED So, I realise my problem is that I was trying to find the item before it was created,
I was binding to a property in xaml that would go off and find an item by a given name, but the item wasnt created at that point in time, if I re-ordered the item in xaml, it works and the item is found... doh!