2

I have a WPF ListBox control which displays items of an RSS feed. I occasionally check the source of the RSS feed for new items. Once I detect a new item I add it to the observable collection which immediately adds the new item to the ListBox display.

Is there a way to 'slide in' the new item from the top, pushing down the existing items? How would I achieve such an effect? Can it be done with a ListBox, or do I need to resort to my own container, such as a StackPanel and animate for example the Height of newly added controls programmatically?

2 Answers 2

5

I just posted an answer to this question which is very similar to yours.

WPF how to animate a list of components

Sign up to request clarification or add additional context in comments.

1 Comment

Nice one -- using a general-purpose animating panel, and then slotting that in via ItemsPanel, is neatly modular and beautifully idiomatic. Thank you!
2

It can be done with a ListBox. Use the ItemContainerStyle to style the ListBoxItems that the binding creates for you: this style can include animations, e.g. by adding an EventTrigger for the Loaded event to the Style.Triggers, and transforms. For example, in your trigger action you could animate the Height so the item expands into place, or if the height is unknown you could have your style set a ScaleTransform and in your trigger action animate the ScaleY of that transform from 0 to 1.

2 Comments

This seems doable, but I am running into problems with having Bindings in the StoryBoard (I am binding to the IsNew property so I am only animating new items, not all items when the ListBox is loaded initially).
I'm not sure what the IsNew property is, but that would probably be part of a trigger rather than a binding in the storyboard; depends how you're doing it. You'd need to post some more details to diagnose the issue; but I'd suggest as a first step you put this aside and explore Josh's solution instead (it's far neater), and come back to mine only if his doesn't work for your scenario.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.