1
votes

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?

1
Can you post your code. It would help.ChrisF

1 Answers

2
votes

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.