Based on the above solution, I tweaked the code so you can pas in a WPF window with tab controls or other containers, and it will loop through all the textbox controls. The TB controls are added to a visual items list and with the returned list you can do whatever you like.
Remove the where clause to remove the restriction for only empty textboxes. Don't forget to close the bracket after (parent) )
Remove this ==> .Where(tb => tb.Text == String.Empty))
<pre>public class cEnumControls
{
public static List<Visual> EnumVisual(UIElement Parent, List<Visual> collection)
{
foreach (var tb in FindVisualChildren<TextBox>(Parent).Where(tb => tb.Text == String.Empty))
{
collection.Add((Visual)tb);
}
return collection;
}
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject obj) where T : DependencyObject
{
if (obj != null)
{
if (obj is T)
yield return obj as T;
foreach (DependencyObject child in LogicalTreeHelper.GetChildren(obj).OfType<DependencyObject>())
foreach (T c in FindVisualChildren<T>(child))
yield return c;
}
}
}