程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> 利用SilverLight 遍歷父子控件通用方法

利用SilverLight 遍歷父子控件通用方法

編輯:關於JSP

利用silverlight 遍歷父子控件通用方法

silverlight中datagrid找元素,真是麻煩,沒有rows對象,無法遍歷。從網上找來這些方法,挺好用的:

public class vthelper()
{
        public t getparentobject<t>(dependencyobject obj, string name) where t : frameworkelement
        {
            dependencyobject parent = visualtreehelper.getparent(obj);

            while (parent != null)
            {
                if (parent is t && (((t)parent).name == name | string.isnullorempty(name)))
                {
                    return (t)parent;
                }
                parent = visualtreehelper.getparent(parent);
            }
            return null;
        }

        public t getchildobject<t>(dependencyobject obj, string name) where t : frameworkelement
        {
            dependencyobject child = null;
            t grandchild = null;

            for (int i = 0; i <= visualtreehelper.getchildrencount(obj) - 1; i++)
            {
                child = visualtreehelper.getchild(obj, i);

                if (child is t && (((t)child).name == name | string.isnullorempty(name)))
                {
                    return (t)child;
                }
                else
                {
                    grandchild = getchildobject<t>(child, name);
                    if (grandchild != null)
                        return grandchild;
                }
            }
            return null;
        }

        public list<t> getchildobjects<t>(dependencyobject obj, string name) 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).name == name || string.isnullorempty(name)))
                {
                    childlist.add((t)child);
                }
                childlist.addrange(getchildobjects<t>(child,""));
            }
            return childlist;
        }
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved