WPF: How to animate a list of components?

前端 未结 1 1600
-上瘾入骨i
-上瘾入骨i 2020-12-18 11:29

Let\'s say I have a list of visual objects (CustomControls). They could be inside a StackPanel or be items on a ListView, I think the container is part of the answer to this

相关标签:
1条回答
  • 2020-12-18 11:40

    Have a look at Kevin Moore's AnimatingTilePanel. When elements are added to or removed from the panel, the rest of the items are animated to move out of the way or occupy the left over space. You would want to do something similar except based on StackPanel logic.

    You want to approach the problem in two parts though. The second would presumably be much easier.

    1. Create a panel (not a control) that animates its children the way you want.
    2. Create a ListBox template that specifies an ItemsPanelTemplate that uses your new panel instead of the default stack panel.

    In the end, the idea is that you don't need to create a custom ListBox control at all. Your interactions with the ListBox (which would be through its Items property or preferably a bound collection) would be done exactly the same as if there were no animation at all. You would rely upon the custom Panel class to do the work of providing the animation.

    UPDATE
    I also found this sample, AnimatedLayoutPanel which is very similar but there's a nice Silverlight-based showcase.

    0 讨论(0)
提交回复
热议问题