/// <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);
            }
        }
posted on 2011-10-26 11:11  arong.NET  阅读(166)  评论(0编辑  收藏  举报