2017-03-17 107 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); 
}