silverlight 获取不到tabcontrol下的所有子控件
用List<TextBox>sw=GetChildObjects<TextBox>(this.LayoutRoot);只能获取tabcontrol第一个tab下的子控件,...
用 List<TextBox> sw = GetChildObjects<TextBox>(this.LayoutRoot); 只能获取tabcontrol第一个tab下的子控件,而其他tab下的子控件获取不到,要怎么才能获取到其他tab下子控件
private List<T> GetChildObjects<T>(DependencyObject obj) where T : FrameworkElement
{ DependencyObject child = null;
List<T> childList = new List<T>();
for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
{ child = VisualTreeHelper.GetChild(obj, i);
if (child is T)
{ childList.Add((T)child); }
childList.AddRange(GetChildObjects<T>(child));
} return childList;
} 展开
private List<T> GetChildObjects<T>(DependencyObject obj) where T : FrameworkElement
{ DependencyObject child = null;
List<T> childList = new List<T>();
for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
{ child = VisualTreeHelper.GetChild(obj, i);
if (child is T)
{ childList.Add((T)child); }
childList.AddRange(GetChildObjects<T>(child));
} return childList;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询