I have a ListBox which is not virtualizing. I am obviously missing something, but cannot find it.
It's actually a ListBox within a ListBox. The outer ListBox has an ItemTemplate which contains an Expander. The Expander is used to display a group of items. The content of the Expander is the second ListBox which displays the items. The ItemTemplate on the second ListBox is bound to the actual Item to display. The ViewModel class for my items has a number of properties which do not initialize data until the property Get is called. However, WPF is walking through every item and causing initialization logic, which I'm trying to avoid.
I discovered that using the ListCollectionView.GroupDescription causes a ListBox to not Virtualize. Now I am handling my own grouping in the ViewModel. My outer ListBox is bound to an ObservableCollection(ItemGroupViewModel), where ItemGroupViewModel has a GroupName and a list of Items. The second ListBox is bound to the Items in the ItemGroupViewModel. This did not fix the problem. I also checked VirtualizingStackPanel.GetIsVirtualizing() while debugging and it returns true, but WPF is still walking through every item. I've double checked to ensure my grouping logic does not fire off the data initialization logic in each item, which I'm trying to avoid.
I thought the IsSharedSizeScope could cause the ListBox to render all items in order to determine column sizing. So I turned SharedSizeScope off. Still no virtualization.
What am I missing?