2013-04-27 43 views

回答

0

使用此。

private static T FindVisualChild<T>(DependencyObject obj, string name) 
     where T : FrameworkElement 
    { 
     for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) 
     { 
      DependencyObject child = VisualTreeHelper.GetChild(obj, i); 
      if (child != null && child is T && child.Name == name) 
       return (T) child; 
      else 
      { 
       T childOfChild = FindVisualChild<T>(child); 
       if (childOfChild != null) 
        return childOfChild; 
      } 
     } 
     return null; 
    } 

像這樣

Button mybtnSave = FindVisualChild<Button>(frameobject, "btnSave"); 
相關問題