I\'m looking for a way to find all controls on Window by their type,
for example: find all TextBoxes
, find all controls implementing specific i
For this and more use cases you can add flowing extension method to your library:
public static List FindAllChildren(this DependencyObject dpo, Predicate predicate)
{
var results = new List();
if (predicate == null)
return results;
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dpo); i++)
{
var child = VisualTreeHelper.GetChild(dpo, i);
if (predicate(child))
results.Add(child);
var subChildren = child.FindAllChildren(predicate);
results.AddRange(subChildren);
}
return results;
}
Example for your case:
var children = dpObject.FindAllChildren(child => child is TextBox);