[英]WPF Animation on listbox items
Any idea what approach I would follow to get the items of a databound listbox to "fly" into the their position in the listbox similarly to the effect you see when a deck of cards is dealt in those Windows Card Games? 知道我会遵循什么方法让数据绑定列表框的项目“飞”到他们在列表框中的位置,就像你在那些Windows Card游戏中处理一副牌时所看到的效果一样? (I'm using WPF)
(我正在使用WPF)
You would need to extend the Panel
class and use it as the ItemsPanelTemplate
of your ListBox.ItemsPanel
property. 您将需要延长
Panel
类,并把它作为ItemsPanelTemplate
您的ListBox.ItemsPanel
财产。 It's really easy... there's just two methods to override; 它真的很容易......只有两种方法可以覆盖; one to measure the items in the
ListBox
and one to arrange them. 一个用于测量
ListBox
的项目,另一个用于排列它们。 Here is a microsoft article on the subject. 这是一篇关于这个主题的微软文章 。
Here is perhaps a more useful article [unfortunately, no longer available] that shows how to animate the items. 这可能是一篇更有用的文章 [不幸的是,不再可用],展示了如何为项目设置动画。 For your effect, you would simply set the from value on your position animations to be the same location just off the viewable area for each of your items.
为了您的效果,您只需将位置动画的起始值设置为您的每个项目的可视区域之外的相同位置。 For example, using a from position of
0, finalSize.Height
would mean that each item would slide to its position from the bottom left corner of the ListBox
. 例如,使用from位置
0, finalSize.Height
意味着每个项目将从ListBox
左下角滑动到其位置。 You could use your new animated Panel
as follows: 您可以使用新的动画
Panel
,如下所示:
<ListBox>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<YourXmlNamespace:YourAnimatedPanel AnyCustomProperty="value" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.