public List<T> GetChildObjects<T>(DependencyObject obj, Type typename) 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 && (((T)child).GetType() == typename))
{
childList.Add((T)child);
}
childList.AddRange(GetChildObjects<T>(child, typename));
}
return childList;
}

使用部分:

 List<TextBlock> listTextBlock = GetChildObjects<TextBlock>(dgSimple, typeof(TextBlock));
dgSimple:父元素name

最新文章

  1. [BZOJ1861][Zjoi2006]Book 书架
  2. MathType应用:批量改变公式格式
  3. 使用 KGDB 调试 Kernel On Red Hat Linux
  4. 智能车学习(三)&mdash;&mdash; ADC学习
  5. 非链接方式访问数据库--查询的数据集用Dataset来存储。
  6. JavaScript:window窗口对象
  7. 添加Microsoft SQL JDBC driver 到 Maven
  8. webpShere中数据库集群url的设置
  9. 20169210《Linux内核原理与分析》第五周作业
  10. weekend110(Hadoop)的 第七天笔记
  11. Jquery 改变样式
  12. ubuntu 14.04 安装 rabbitmq
  13. Error fetching command &#39;collectstatic&#39;: You&#39;re using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. Command &#39;collectstatic&#39; skipped
  14. mysql oracle 数据库备份
  15. Python爬虫学习——布隆过滤器
  16. VNPY思维导图架构
  17. centos下同时启动多个tomcat
  18. Flutter - 添加从左向右滑动,返回上一个页面
  19. PMP模拟考试-2
  20. CMD模拟http请求

热门文章

  1. 02#Vue3 Transition 过渡:切换路由组件
  2. JavaScript之this、let、const关键字
  3. Linux数据实时同步(sersync+rsync)
  4. Vulnhub:katana靶机
  5. 2023 年 CCF 春季测试赛模拟赛 - 2
  6. 实践:腾讯云IM搭建应用内类微信社交聊天模块
  7. Note Taking App Comparison: Notesnook vs Joplin
  8. FMC子卡设计资料原理图:FMC550-基于ADRV9002双窄带宽带射频收发器FMC子卡
  9. vue中vue2-google-maps使用谷歌地图的基础操作
  10. win10多用户