Reputation: 43
I can get all UI controls on a Form
but how to find controls on a certain UserControl
?
Upvotes: 4
Views: 10416
Reputation: 5234
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?
Upvotes: 1
Reputation: 29000
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
Upvotes: 5