记得原来博客园有人写过下雪的程序,今天正好是平安夜大家看看这个下雪效果如何:
Blend Behavior代码如下:
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(); } }@H_403_102@源代码下载
参考资料
http://www.kirupa.com/blend_silverlight/falling_sNow_silverlight_pg1.htm 总结以上是内存溢出为你收集整理的Silverlight 圣诞节下雪效果全部内容,希望文章能够帮你解决Silverlight 圣诞节下雪效果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)