How to loop through WPF StackPanel static Items?
问题 Probably very easy but I am having trouble to figure this out (also Google doesn't seem to help much). How can I loop through the statically declared elements (no databinding - elements are declared in the xaml) of a StackPanel? Any help appreciated! 回答1: Do you mean the StackPanel 's children? foreach (var child in stackPanel.Children) { //do something with child } A more generic solution that would work regardless of the parent would be to use LogicalTreeHelper or VisualTreeHelper ,