Use silverlight to traverse parent and child Controls
It is really troublesome to find elements in the datagrid in silverlight. No rows object can be traversed. It is quite useful to find these methods from the Internet:
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;
}
}