wpf 查找指定类型的子元素
2024-10-12 10:43:39
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
最新文章
- [BZOJ1861][Zjoi2006]Book 书架
- MathType应用:批量改变公式格式
- 使用 KGDB 调试 Kernel On Red Hat Linux
- 智能车学习(三)&mdash;&mdash; ADC学习
- 非链接方式访问数据库--查询的数据集用Dataset来存储。
- JavaScript:window窗口对象
- 添加Microsoft SQL JDBC driver 到 Maven
- webpShere中数据库集群url的设置
- 20169210《Linux内核原理与分析》第五周作业
- weekend110(Hadoop)的 第七天笔记
- Jquery 改变样式
- ubuntu 14.04 安装 rabbitmq
- 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
- mysql oracle 数据库备份
- Python爬虫学习——布隆过滤器
- VNPY思维导图架构
- centos下同时启动多个tomcat
- Flutter - 添加从左向右滑动,返回上一个页面
- PMP模拟考试-2
- CMD模拟http请求
热门文章
- 02#Vue3 Transition 过渡:切换路由组件
- JavaScript之this、let、const关键字
- Linux数据实时同步(sersync+rsync)
- Vulnhub:katana靶机
- 2023 年 CCF 春季测试赛模拟赛 - 2
- 实践:腾讯云IM搭建应用内类微信社交聊天模块
- Note Taking App Comparison: Notesnook vs Joplin
- FMC子卡设计资料原理图:FMC550-基于ADRV9002双窄带宽带射频收发器FMC子卡
- vue中vue2-google-maps使用谷歌地图的基础操作
- win10多用户