views:

322

answers:

3

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!

+1  A: 

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
VirtualizingStackPanel is the default ItemsPanel for ListBox.
micahtan
A: 

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
A: 

I can't set VirtualizingStackPanel.IsVirtualizing="False" as it would cause all my windows to use too much space. I really only want the animation to run once. Is there a better event then 'Loaded'?

Thanks

baileybbk