Forcing WPF to create the items in an ItemsControl
问题 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 ListBox in the visual tree, get their text, and then compare that with what I expect the text to be. The problem with this approach is that internally ListBox uses a VirtualizingStackPanel to display its items, so only the items that are visible are created. I eventually came across the ItemContainerGenerator class, which looks like it