We've got a lot of requests lately for adding animations in our own implementation of ListBox for WP7 - the RadDataBoundListbox. So we decided that we will add animations for the following scenarios:
- when the listbox is initially loaded,
- when the listbox is inside Pivot and the selected pivot item is changed,
- when items are added/removed from the ItemsSource and the new/old items are in the viewport of the control.
This functionality will be available very soon out of the box. So in this blog post I'll show you how to create your own implementation of initial loading animation in the listbox. We will use the Telerik animation framework for WP7 and will hook the proper events to call the Tile animation at the correct time.
In this example I'm using the default VS template for creating WP7 databound applications. Then the silverlight listbox is replaced with the Telerik listbox.
Now it is time to add the animations. As I said before, we will use the Tile animation which is part of the Telerik animation framework.
In the Page constructor the following code is added:
This will instruct the TileAnimation that we need to animate the listbox items. Now we need to figure out when is the right moment to run this animation. The right moment to run the animation when the items in the Viewport of the listbox are generated and realized. We can use the ItemStateChanged event to monitor when an item is generated. We can count the number of ViewPort items by using the ViewPortItems collection. Here is the simple code:
Once we know that it is time to run the animation - here is how to actually run it:
This is all we need in order to setup the loading animation for a listbox. If you need any other animation implemented - please let me know!
Valentin Stoychev (@ValioStoychev) for long has been part of Telerik and worked on almost every UI suite that came out of Telerik. Valio now works as a Product Manager and strives to make every customer a successful customer.
Subscribe to be the first to get our expert-written articles and tutorials for developers!