 |
|
 |
|
Location: Blogs Andy's Blog |
|
| Posted by: host |
5/5/2007 10:36 PM |
I was surprised to see that custom timers (like System.Timers.Timer) are not yet supported in Silverlight 1.1 Alpha. These would be great for creating "casual games" such as those that made Flash so popular.
Luckily, I came across this post by Joe Stegman that shows a workaround by using an Animation Timer:
First set up an Animation Timer in your xaml...
< Canvas.Resources> <Storyboard x:Name="timer"> <DoubleAnimation Duration="00:00:0.02" /> </Storyboard> </Canvas.Resources>
Then you can add an "tick" event handler and start up the timer..
timer.Completed += new EventHandler(timer_Completed); timer.Begin();
And finally, make sure you restart the timer in the timer_Completed event.
void timer_Completed(object sender, EventArgs e) { // ... do per tick stuff here...
// restart the timer timer.Begin(); } |
|
| Permalink |
Trackback |
Comments (4)
Add Comment
|
Re: Timers in Silverlight
|
By Anonymous on
11/28/2010 11:48 PM
|
This approach doe NOT work in Silverlight 4 It throws error: Animation target not specified.
|
|
|
Re: Timers in Silverlight
|
By Anonymous on
1/21/2011 3:24 AM
|
|
For me too
|
|
|
Re: Timers in Silverlight 4 FIX
|
By Anonymous on
2/9/2011 1:03 PM
|
|
|
|
|
Re: Timers in Silverlight 4 FIX
|
By Anonymous on
2/9/2011 1:06 PM
|
Storyboard x:Name="timer1" Storyboard.TargetName="_timer" Storyboard.TargetProperty="(UIElement.Opacity)" DoubleAnimation Duration="00:00:2" Rectangle x:Name="_timer" Opacity="0"
|
|
|
|
 |
|
 |
|
|