I'm building a WPF app with a StackPanel of Grids with TextBoxes in them. I need a list of all the TextBoxes. How do I reach two levels deep using Children.OfType() function?
Already tried: https://stackoverflow.com/a/10279201/9985476 but didn't seem to work. Maybe I implemented it wrong?
Sample code:
<StackPanel x:Name="addEmployees">
<Grid>
<TextBox Text="" />
</Grid>
<Grid>
<TextBox Text="" />
</Grid>
<Grid>
<TextBox Text="" />
</Grid>
<StackPanel />
In my code behind i tried something of this sort:
private IEnumerable<TextBox> addEmployeesTB = addEmployees.Children.OfType<Grid>().Children.OfType<TextBox>();
But i get: CS1061 C# does not contain a definition for 'Children' and no accessible extension method 'Children' accepting a first argument of type could be found (are you missing a using directive or an assembly reference?)