The following code snippet is from the Silverlight SDK and I am trying to understand the reason it is the way it is.
Can anyone explain the need for the for
loop?
internal static DependencyObject GetVisualRoot(DependencyObject d)
{
DependencyObject root = d;
for (; ; )
{
FrameworkElement element = root as FrameworkElement;
if (element == null)
{
break;
}
DependencyObject parent = element.Parent as DependencyObject;
if (parent == null)
{
break;
}
root = parent;
}
return root;
}