Home  >  

Scripted Animation in Silverlight

Author photo
AddThis Social Bookmark Button

For any developer moving into Silverlight from Flash, one quickly notices that there is no enter frame event in Silverlight. Each Silverlight control does not inherently have a timeline, but instead can have any number of storyboards. A nice way to create your own enter frame event is by using storyboard looping.

Storyboard looping can be done in a handful of ways, but since I’m writing about scripted animation, I’ll talk about creating your storyboard using c#.

First, you create a new storyboard (called sb in my example). Second, you add an event handler for the storyboard completed event. Third, you add the event to the controls resources. Finally, you start your newly created storyboard.


sb = new Storyboard();
sb.Completed += new EventHandler(sbCompleted);
this.Resources.Add(“sb”, sb);
sb.Begin();


In the sbCompleted method, you just start the storyboard, thus creating the loop.
The sbCompleted method is also where you would put your enter frame logic.

void sbCompleted(oject sender, EventArgs e)
{
	
    // some enter frame logic...
    sb.Begin();

}

This technique, along with extending your silverlight control’s properties, to match the properties you may already have for a Flash project will give you a way to port ActionScript logic to c# and Silverlight.

Read more from Jeremy Bierly. Jeremy Bierly's Atom feed

Comments

Leave a comment


Tag Cloud

Poll: Mobile Features

What feature do you use most on your mobile phone?

Vote | View Poll Results | Read Related Blog Entry

Latest Features

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.