wpf 遍历listview 时 传入指定类型 得到指定类型控件info

时间:2021-06-10 15:14:30
private ChildType FindVisualChild<ChildType>(DependencyObject obj) where ChildType : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj,i);
if (child!=null&& child is ChildType)
{
return child as ChildType;
}
else
{
ChildType childOfChildren = FindVisualChild<ChildType>(child);
if (childOfChildren!=null)
{
return childOfChildren;
}
}
}
return null; }