获取RootVisual中的RootLayout
UIElement rootVisual = Application.Current.RootVisual;
Panel panel = rootVisual as Panel;
if (panel == null)
{
int childrenCount = System.Windows.Media.VisualTreeHelper.GetChildrenCount(rootVisual);
for (int i = 0; i < childrenCount; i++)
{
DependencyObject child = System.Windows.Media.VisualTreeHelper.GetChild(rootVisual, i);
panel = child as Panel;
if (panel != null)
{
break;
}
}
}
Panel panel = rootVisual as Panel;
if (panel == null)
{
int childrenCount = System.Windows.Media.VisualTreeHelper.GetChildrenCount(rootVisual);
for (int i = 0; i < childrenCount; i++)
{
DependencyObject child = System.Windows.Media.VisualTreeHelper.GetChild(rootVisual, i);
panel = child as Panel;
if (panel != null)
{
break;
}
}
}