Friday, May 31, 2013

Find Parent Framework Element in silverligth

Sometime we need to find out the specific frame work element's ancestors. Example- If we use any pop up in any position in our application then there will need to hide it when we click on any where in the application.

private FrameworkElement FindControlParent(FrameworkElement control)

{

FrameworkElement ctrlParent = control;
//check is it user cotrol
while (typeof(UserControl) != null)

{
//get current control parent
ctrlParent = (FrameworkElement)ctrlParent.Parent;
//check current control has no parent; If not then it is the ancestor of my sending control last parent
if (ctrlParent.Parent == null)

{

return (FrameworkElement)ctrlParent;

}

}

return null;

}

No comments:

Post a Comment