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

 

相关文章:

  • 2021-08-12
  • 2021-12-23
  • 2022-12-23
  • 2021-05-19
  • 2021-12-21
  • 2021-11-27
  • 2021-11-04
  • 2021-08-23
猜你喜欢
  • 2021-05-29
  • 2022-03-02
  • 2021-09-08
  • 2021-10-20
  • 2021-07-07
  • 2021-12-22
  • 2021-11-27
相关资源
相似解决方案