[英]How to find all the controls in WPF on a UserControl component
我可以获取Form
上的所有UI控件,但如何在某个UserControl
上找到控件?
You can use Linq operator OfType
and Controls property
您可以使用
Linq operator OfType
和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 链接: http : //msdn.microsoft.com/fr-fr/library/vstudio/bb360913.aspx
您可以查看UserControl
的FindName(字符串)方法
If you only want to look in the immediate object you can do FindName : 如果您只想查看直接对象,可以执行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? 或者如果你想要递归方式,那么你可以在这里查看这篇文章: 如何通过名称或类型找到WPF控件?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.