/// <summary> /// 遍历特定类型子对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parent"></param> /// <returns></returns> public IEnumerable<T> FindChildren<T>(DependencyObject parent) where T : class { var count = VisualTreeHelper.GetChildrenCount(parent); if (count > 0) { for ( var i = 0; i < count; i++) { var child = VisualTreeHelper.GetChild(parent, i); var t = child as T; if (t != null) yield return t; var children = FindChildren<T>(child); foreach ( var item in children) yield return item; } } } void ClearAllTextBox() { IEnumerable<TextBox> AllTextBox = FindChildren<TextBox>( this); foreach ( var textbox in AllTextBox) { textbox.ClearValue(TextBox.TextProperty); } }