开发者

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 t开发者_C百科o the effect you see when a deck of cards is dealt in those Windows Card Games? (I'm using WPF)


You would need to extend the Panel class and use it as the ItemsPanelTemplate of your ListBox.ItemsPanel property. It's really easy... there's just two methods to override; one to measure the items in the ListBox and one to arrange them. 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. You could use your new animated Panel as follows:

<ListBox>
  <ListBox.ItemsPanel>
    <ItemsPanelTemplate>
      <YourXmlNamespace:YourAnimatedPanel AnyCustomProperty="value" />
    </ItemsPanelTemplate>
  </ListBox.ItemsPanel>
</ListBox>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜