如何访问一个ItemsControl的孩子? [英] How do I access the children of an ItemsControl?

查看:120
本文介绍了如何访问一个ItemsControl的孩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从的ItemsControl 衍生的组成部分,我可以访问它的集合的孩子,让我可以通过这些循环来执行某些操作?我似乎无法找到目前没有简单的方法

If i have a component derived from ItemsControl, can I access a collection of it's children so that I can loop through them to perform certain actions? I can't seem to find any easy way at the moment.

推荐答案

具有更好的性能相似,勒布的,但可能是一个解决方案:

A solution similar to Seb's but probably with better performance :

for(int i = 0; i < itemsControl.Items.Count; i++)
{
    UIElement uiElement =
        (UIElement)itemsControl.ItemContainerGenerator.ContainerFromIndex(i);
}

这篇关于如何访问一个ItemsControl的孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆