Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate WP7 datatemplate element when first added to listbox

Hey all, I'm trying to apply an animation to any element that gets added to a datatemplate in WP7's subset of silverlight. I'm having some issues though. While it appears to be quite possible in WPF ( Animate WPF Datatemplate when item added to Listbox? ) using DataTemplate.Triggers, WP7's silverlight doesn't have the Triggers property for DataTemplates. As such, how would I go about doing this on the winphone?

like image 345
jjcm Avatar asked May 22 '11 19:05

jjcm


2 Answers

I am assuming you have a DataTemplate that is used as the ListBox.ItemTemplate property value in XAML? If this is the case, you should be able to handle the Loaded event on the root element of the DataTemplate in code behind. This event will be invoked as each DataTemplate 'instance' is created, alowing you to fire a Storyboard.

like image 115
ColinE Avatar answered Nov 11 '22 14:11

ColinE


Silverlight 4 added the concept of LayoutStates to the ListBoxItem control, this allowed you add animations for state transitions including things like BeforeLoaded to AfterLoaded. Sadly this functionality isn't baked into WP7 (based on Silverlight 3).

There are some workarounds till that changes with the "Mango" release, including the solution ColinE mentions.

Some resources are: Animate your #WP7 ListBoxItems while being un-/loaded and Reactive Extensions #3: Windows Phone 7

like image 41
Nigel Sampson Avatar answered Nov 11 '22 14:11

Nigel Sampson