获取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;
                    }
                }
            }

 

posted on 2009-10-29 17:26  think8848  阅读(766)  评论(0编辑  收藏  举报