0

I have a trigger on a storyboard for my listboxitem where the trigger is 'Loaded'. It appears that every time the listbox scrolls the item gets the 'Loaded' event. I really only want the storyboard to run once, when the listboxitem gets displayed.

I assumed that the Loaded event would only get triggered once.

Any help would be great.

Thanks!

H.B.
  • 166,899
  • 29
  • 327
  • 400

2 Answers2

1

I'm not sure if you can have it run only once or not. Most times the ListBox uses a VirtualizingStackPanel for its ItemsPanel. This causes only those ListBoxItems that are visible (or nearly visible) to be created and added to the visual tree. Once you scroll away, the items that were visible are destroyed, and then the newly visible items are created. Each time that you scroll to an item, it would be recreated, and thus its Loaded event will fire.

Andy
  • 30,088
  • 6
  • 78
  • 89
0

You could try setting VirtualizingStackPanel.IsVirtualizing="False" for your listbox, that should do it. Be aware that this consumes more resources since items will always be there no matter if you see them in the list or not. Shouldn't be a problem though if you don't have too many items in it.

Botz3000
  • 39,020
  • 8
  • 103
  • 127