Coded UI Tests: How do I get a strongly typed WpfList control collection?

Question

Our application has a WPF ListBox that generates ListItems from a data source according to a Data Template. If I view the ListBox in the Coded UI Test Builder, I see a List, ListItems, and one custom child control per ListItem. I have modified the XAML for the custom control to bind the AutomationId to a unique identifier, so that's not a problem.

I don't always know which control I want (which I could access by Automation Id). Sometimes I need to access them by index or as an entire collection. However, the generated WpfList class's Items property indexes the ListItems, not the custom child controls.

What's the best way to get at the child control in each ListItem and still use it like a control collection (position and name indexing, IEnumerable<T> implementation, etc.)?

There is no caching, so every access to the indexers or ToList() will produce another copy of the custom control(s). I could add caching (an internal List<T>) but the performance is acceptable for now. I'm only ever asking for one list item (by indexer) or getting the list once or twice per test (by ToList()).

The final touch was an extended WpfList class that takes a custom control type and provides a new WpfCustomCollection<T> property.

What I want is some new control collection that exposes the items in the ListBox as an ICollection<MyCustomControl>. (This is the way I see it. There may be another way. See the examples below.) Consider the following class as my custom child control.

There is no caching, so every access to the indexers or ToList() will produce another copy of the custom control(s). I could add caching (an internal List<T>) but the performance is acceptable for now. I'm only ever asking for one list item (by indexer) or getting the list once or twice per test (by ToList()).

The final touch was an extended WpfList class that takes a custom control type and provides a new WpfCustomCollection<T> property.