码迷,mamicode.com
首页 > 其他好文 > 详细

遍历控件

时间:2014-09-24 17:20:27      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:for   sp   c   工作   ad   new   r   bs   return   

1.平时工作中用到的

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;
        }

遍历控件

标签:for   sp   c   工作   ad   new   r   bs   return   

原文地址:http://www.cnblogs.com/wuyp-shodow/p/3990647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!