I want to verify that the items in my ListBox
are displayed correctly in the UI. I figured one way to do this is to go through all of the children of the
For anyone else wondering about this, in Andy's case, perhaps swapping out the VirtualizingStackPanel with a normal StackPanel would be the best solution here.
The reason calling PrepareItemContainer on the ItemContainerGenerator isn't working is that an item must be in the visual tree for PrepareItemContainer to work. With a VirtualizingStackPanel, the item won't be set as a visual child of the panel until the VirtualizingStackPanel determines that it is/is about to be on screen.
Another solution (the one I use) is to create your own VirtualizingPanel, so you can control when items are added to the visual tree.