如何遍历WPF StackPanel静态项? [英] How to loop through WPF StackPanel static Items?
本文介绍了如何遍历WPF StackPanel静态项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能非常简单,但是我很难弄清楚这一点(而且Google似乎没有太大帮助).
Probably very easy but I am having trouble to figure this out (also Google doesn't seem to help much).
如何遍历StackPanel的静态声明的元素(没有数据绑定-在xaml中声明了元素)?
How can I loop through the statically declared elements (no databinding - elements are declared in the xaml) of a StackPanel?
任何帮助表示赞赏!
推荐答案
您是指StackPanel
的孩子吗?
foreach (var child in stackPanel.Children)
{
//do something with child
}
一个更通用的解决方案,不管父级是哪个,都可以使用LogicalTreeHelper
或VisualTreeHelper
,这取决于您希望遍历的WPF树:
A more generic solution that would work regardless of the parent would be to use LogicalTreeHelper
or VisualTreeHelper
, depending on what WPF tree you wish to traverse:
foreach (var child in LogicalTreeHelper.GetChildren(stackPanel))
{
//do something with child
}
这篇关于如何遍历WPF StackPanel静态项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文