wpf 寻找某个控件下的子控件
/// <summary> /// 寻找某个控件下的子控件 /// </summary> /// <typeparam name="ChildType"></typeparam> /// <param name="obj"></param> /// <returns></returns> 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; }
至少证明我们还活着