2017-03-17 1 views
-1

특정 wrappanel의 단추를 코드의 배열이나 목록에 추가하는 방법이 있습니까? 나는 아래의 코드를 시도했지만 작동하지 않습니다 :랩 패널에서 단추 배열에 단추 추가

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

답변

1

당신은 자식에 액세스 할 수 wrappanel.children를 지정해야합니다.

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

당신은 Linq에 사용할 수 :

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

PanelChildren 속성이 UIElement 객체의 모든 유형을 포함 할 수있는 UIElementCollection를 반환하기 때문에, 당신은에 OfType LINQ 확장 방법을 사용할 수 있습니다 만 PIN이 Button 요소 :

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