I can get all UI controls on a Form
but how to find controls on a certain UserControl
?
Asked
Active
Viewed 9,901 times
4

Konrad Viltersten
- 36,151
- 76
- 250
- 438

Fedor
- 43
- 1
- 3
3 Answers
5
You can use Linq operator OfType
and Controls property
var controls = YourForm
.YourUserControl
.Controls.OfType<TextBox>();
foreach(var control in controls)
{
....
}
Link : http://msdn.microsoft.com/fr-fr/library/vstudio/bb360913.aspx

Aghilas Yakoub
- 28,516
- 5
- 46
- 51
-
4I used this but the ".Controls" turned red, why? It says, Cannot Resolve Controls – Kokombads Dec 01 '14 at 04:21
1
If you only want to look in the immediate object you can do FindName:
object foundControl = someParentControl.FindName("nameOfChild");
or if you want recursive ways then you can look at this post here: How can I find WPF controls by name or type?

Community
- 1
- 1

Bill Tarbell
- 4,933
- 2
- 32
- 52
-
This is no good if you want *all* the controls and you don't care or know what their names are. – Ben Sep 09 '17 at 16:37