Christmas snow Effect of Silverlight

Source: Internet
Author: User

I remember someone wrote about snow in the blog Park.ProgramToday is Christmas Eve. Let's see how the snow works:

 

 

Blend BehaviorCodeAs follows:

 Public class  Fallingsnowbehavior : Behavior < Canvas > {Private Static  Random Randomnumber; Protected override void Onattached (){ Base . Onattached (); randomnumber = New  Random (); This . Associatedobject. Loaded + = New  Routedeventhandler (Applicationloaded );} Void Applicationloaded ( Object Sender, Routedeventargs E ){Foreach ( Frameworkelement Element In this . Associatedobject. Children ){ Frameworkelement Localcopy = element; Double Yposition = Canvas . Gettop (localcopy ); Double Xposition = Canvas . Getleft (localcopy ); Double Speed = 2 * randomnumber. nextdouble (); Double Counter = 0;Double Radius = 30 * speed * randomnumber. nextdouble (); localcopy. Opacity = 0.2 + randomnumber. nextdouble (); Compositiontarget . Rendering + = Delegate ( Object O, Eventargs Arg) {counter + = Math . PI/(180 * speed ); If (Yposition < Application . Current. rootvisual. desiredsize. Height) {yposition + = 0.2 + speed ;} Else {Yposition =-localcopy. height ;} Canvas . Settop (localcopy, yposition ); Canvas . Setleft (localcopy, xposition + radius * Math . Cos (Counter ));};}} Protected override void Ondetaching (){ Base . Ondetaching ();}}

Source codeDownload

 

References

Http://www.kirupa.com/blend_silverlight/falling_snow_silverlight_pg1.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.