I have a ListBox that I bind to an ItemsSource, like this:
var foos = new ObservableCollection<Foo> { foo1, foo2, foo3 };
var listBox = new ListBox { ItemsSource = _foos };
Now I want to do some operations right away on the ListBoxItems that holds the items, but they don't seem to be created right away. Are they? Is there some event I can listen to in order to be notified, or am I simply trying to fetch the ListBoxItem's in an invalid way? I am doing it like this (and have verified that it works somewhere I know the ListBox is "ready"):
var lbi = listBox.ItemContainerGenerator.ContainerFromItem(foo1) as ListBoxItem;
Note that this is being done in a unit test, so I guess the ListBox is never rendered. Is that why the ListBoxItems aren't created? And can I manually trigger the creation of the ListBoxItems somehow?