Search code examples
c#wpfitemscontrol

How do I access the children of an 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.


Solution

  • 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);
    }