以下代码片段来自 Silverlight SDK,我试图了解它的原因。谁能解释for
循环的必要性?
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;
}