WPF:如何动画的组件列表?组件、动画、列表、WPF

2023-09-03 01:11:34 作者:清欢

让我们说我有可视对象(CustomControls)的列表。他们可能是一个StackPanel的内部或上一个ListView项目,我认为容器是回答这个问题的一部分。

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 question.

在视觉上,你可以把这些对象在队列中的项目。每次我弹出此队列的底部有一个对象,我想用弹出对象外出的观点框架和新的动画,整个​​队列(想象观看框架只显示一个子集)与滑动元件的其余部分。

Visually, you can think of these objects as items on a queue. Every time I pop an object from the bottom of this queue, I'd like to animate the whole queue with the popped object going out of the view frame and the new one (imagine that the viewing frame only displays a subset) sliding in with the rest of the elements.

什么是创建这个动画是最好的方法,什么是最好的容器呢?

What's the best approach to create this animation and what's the best container for it?

推荐答案

有一个看看凯文·穆尔的AnimatingTilePanel.当元素被添加到或从面板上拆除,对其余项目的动画迁出的方式还是占据遗留下来的空间。你会想这样做,除了基于StackPanel的逻辑类似的东西。

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.

您想虽然解决这个问题两部分。第二个将presumably容易得多。

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

创建一个面板(而不是控件)动画的孩子,你想要的方式。 创建一个列表框模板,定义了一个ItemsPanelTemplate使用默认堆面板的新的面板来代替。 Create a panel (not a control) that animates its children the way you want. Create a ListBox template that specifies an ItemsPanelTemplate that uses your new panel instead of the default stack panel.

在最后,这个想法是,你并不需要创建一个自定义列表框控件的。您的列表框(这将是通过其项目属性或preferably绑定的集合)的相互作用将做完全一样的,如果没有动画的。你会依靠自定义面板类做提供动画的工作。

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.

更新 我也发现了这个样品,AnimatedLayoutPanel这是非常相似,但有一个很好的基于Silverlight的展示。

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