最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
利用SilverLight 遍历父子控件通用方法
时间:2022-06-29 02:40:11 编辑:袖梨 来源:一聚教程网
利用silverlight 遍历父子控件通用方法
silverlight中datagrid找元素,真是麻烦,没有rows对象,无法遍历。从网上找来这些方法,挺好用的:
public class vthelper()
{
public t getparentobject(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
(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(child, name);
if (grandchild != null)
return grandchild;
}
}
return null;
}public list
getchildobjects (dependencyobject obj, string name) where t : frameworkelement
{
dependencyobject child = null;
listchildlist = new list (); 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(child,""));
}
return childlist;
}
}
相关文章
- 以闪亮之名店长体验流霞季怎么玩 缘溪临霞套装活动介绍 12-31
- 未定事件簿旧梦新生左然篇怎么玩 旧梦新生左然篇活动介绍 12-31
- 未定事件簿左然破浪远行怎么样 12-31
- 桃源深处有人家行医问诊怎么玩 12-31
- 恋与制作人跨年福利有哪些 恋与制作人跨年福利内容介绍 12-31
- 阴阳师协同对弈大乱斗怎么玩 阴阳师协同对弈大乱斗活动介绍 12-31