• silverlight遍历子元素 Get Descendant ,Childern


    项目中遇到需要获取一个元素的所有子元素或后代元素, 系统有FindName("Name"),但我们需要的元素大部分都没有name,而且FindName只能返回一个结果。我们扩展了  方法,解决的获取所有子元素或后代元素

           public static List<DependencyObject> GetChildern(this DependencyObject root)
            {
                if (root == null)
                    return null;
                int count = VisualTreeHelper.GetChildrenCount(root);
                if (count <= 0)
                    return null;
                List<DependencyObject> child = new List<DependencyObject>();
                for (int i = 0; i < count; i++)
                {
                    DependencyObject c = VisualTreeHelper.GetChild(root, i);
                    if (c != null)
                        child.Add(c);
                }
                return child;
            }

            public static List<DependencyObject> GetDescendants(this DependencyObject root)
            {
                if (root == null)
                    return null;
                List<DependencyObject> temp = root.GetChildern();
                if (temp == null || temp.Count == 0)
                    return null;
                List<DependencyObject> ds = new List<DependencyObject>();          
                ds.AddRange(temp);
                foreach (var t in temp)
                {
                    List<DependencyObject> list = t.GetDescendants();
                    if (list != null && list.Count > 0)
                        ds.AddRange(list);
                }
                return ds;          
            }

  • 相关阅读:
    Sqlite3:Sqlite3命令行Linux操作
    Docker:docker部署Sqlite3数据库
    SpringBoot:Sqlite3+SpringBoot2.1.3+Mybatis-Puls整合项目
    Algorithm:Java加密解密之MAC(消息认证码)
    Springboot:SpringBoot2.0整合WebSocket,实现后端数据实时推送!
    windows10系统安装anaconda后CMD命令行里面的python默认版本变化的问题
    在树莓派中,minicom的一些使用方法
    树莓派软硬串口对调
    树莓派无显示屏连接wifi教程
    设备管理器添加到桌面
  • 原文地址:https://www.cnblogs.com/mjgb/p/2084277.html
Copyright © 2020-2023  润新知