2017-03-17 108 views

回答

1

您必須指定wrappanel.children來訪問它的孩子。

foreach (Button b in nameOfWrappanel.Children) 
{ 
    list.Add(b); 
} 
1

你可以使用Linq:

var buttons = myWrapPanel.Children.OfType<Button>().ToList(); 
0

由於PanelChildren屬性返回UIElementCollection可能包含任何類型的UIElement的對象,你可以使用OfType LINQ擴展方法只retrive的Button elements:

foreach (Button b in nameOfWrappanel.Children.OfType<Button>()) 
{ 
    list.Add(b); 
}