Reputation: 83366
I've got a user control that I'm using as my DataTemplate for all the items in my ListBox. There's an animation in said UserControl that's pretty simple - it just expands a certain ListBox, and it works. The thing is, when I scroll, every Nth item ALSO has the ListBox expanded, where N depends on how big my browser is sized to (in other words, how many items the ListBox is holding at any one time.)
It seems as though new items getting loaded into the listbox as I scroll are tripping over this animation. Is there anything I can do about this?
Upvotes: 1
Views: 239
Reputation: 189495
If your outer ListBox contains only a few items then add this to its Xaml:-
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItesmPanelTemplate>
</ListBox.ItemsPanel>
By default the ListBox uses a VirtualizingStackPanel
which only contains concrete instances of ListBoxItem
that are currently being displayed. Items a generated as needed by a ItemContainerGenerator
which will recycle existing items. I suspect some in there the state of an ListBoxItem
is not entirely cleared when re-used to display another item from the ItemsSource.
Upvotes: 2