Windows Phone开发中时钟案例解析

移动开发
Windows Phone开发有很多值得学习的地方,本文向大家简单介绍一下Windows Phone开发中一个时钟的例子,希望对你的学习有所帮助。

本文和大家重点讨论一下Windows Phone开发中一个时钟的例子,Expressblend工具是开发silverlightUi的重要工具,在这里有一个从silverlight移植过来的时钟小例子可以看出在Phone7上这个工具一样也很重要并且可以提高开发效率。

Windows Phone开发中一个时钟的例子

Expressblend工具是开发silverlightUi的重要工具,在这里有一个从silverlight移植过来的时钟小例子可以看出Windows Phone开发中在Phone7上这个工具一样也很重要并且可以提高开发效率。

一.在blend工具中,可以用Ellipse绘制表盘,通过在property中使用渐变色来产生立体效果。还可以能过gradient工具来调整渐变色。

 

 

 

 

 

 

二.用Ellipse工具绘制表针轴,并设置圆的strokethickness来改变线的粗细。

 

 

三.用Rectangle工具来绘制三个表针,并放好位置。

 

 

四.增加动画效果

  1. <Storyboardx:NameStoryboardx:Name="clockStoryboard"> 
  2. <!--Thisanimationtargetsthehourhandtransform--> 
  3. <DoubleAnimationx:NameDoubleAnimationx:Name="hourAnimation" 
  4. Storyboard.TargetName="HourHandTransform" 
  5. Storyboard.TargetProperty="Angle" 
  6. Duration="12:0:0"RepeatBehavior="Forever"To="360"/> 
  7.  
  8. <!--Thisanimationtargetstheminutehandtransform--> 
  9. <DoubleAnimationx:NameDoubleAnimationx:Name="minuteAnimation" 
  10. Storyboard.TargetName="MinuteHandTransform" 
  11. Storyboard.TargetProperty="Angle" 
  12. Duration="1:0:0"RepeatBehavior="Forever"To="360"/> 
  13.  
  14. <!--Thisanimationtargetsthesecondhandtransform--> 
  15. <DoubleAnimationx:NameDoubleAnimationx:Name="secondAnimation" 
  16. Storyboard.TargetName="SecondHandTransform" 
  17. Storyboard.TargetProperty="Angle" 
  18. Duration="0:1:0"RepeatBehavior="Forever"To="360"/> 
  19. </Storyboard> 
  20.  

 

Windows Phone开发中这时运行一下此程序,已经可以看到时钟的表针在走了。

五.控制表针行为语句

  1. voidMainPage_Loaded(objectsender,RoutedEventArgse)  
  2. {  
  3. //Thecurrentdateandtime.  
  4. System.DateTimecurrentDate=DateTime.Now;  
  5.  
  6. //Findtheappropriateangle(indegrees)forthehourhand  
  7. //basedonthecurrenttime.  
  8. doublehourangle=(((float)currentDate.Hour)/12)*360+currentDate.Minute/2;  
  9.  
  10. //Thesameasfortheminuteangle.  
  11. doubleminangle=(((float)currentDate.Minute)/60)*360;  
  12.  
  13. //Thesameforthesecondangle.  
  14. doublesecangle=(((float)currentDate.Second)/60)*360;  
  15.  
  16. //Setthebeginningoftheanimation(Fromproperty)totheangle  
  17. //correspongingtothecurrenttime.  
  18. hourAnimation.From=hourangle;  
  19.  
  20. //Settheendoftheanimation(Toproperty)totheangle  
  21. //correspondingtothecurrenttimePLUS360degrees.Thus,the  
  22. //animationwillendaftertheclockhandmovesaroundtheclock  
  23. //once.Note:TheRepeatBehaviorpropertyoftheanimationisset  
  24. //to"orever"sotheanimationwillbeginagainassoonasitcompletes.  
  25. hourAnimation.To=hourangle+360;  
  26.  
  27. //Sameaswiththehouranimation.  
  28. minuteAnimation.From=minangle;  
  29. minuteAnimation.To=minangle+360;  
  30.  
  31. //Sameaswiththehouranimation.  
  32. secondAnimation.From=secangle;  
  33. secondAnimation.To=secangle+360;  
  34.  
  35. this.clockStoryboard.Begin();  
  36. }  
  37.  

 

源代码:

/Files/randylee/MyClock.rar

责任编辑:佚名 来源: cnblogs.com
相关推荐

2010-05-11 16:47:32

Windows Pho

2010-05-08 16:36:16

Windows Pho

2010-06-11 16:01:26

Windows Pho

2010-03-09 10:51:15

Windows Pho

2010-04-08 17:40:23

Windows Pho

2010-06-09 16:13:23

Windows Pho

2013-07-30 10:44:31

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2012-05-08 13:54:40

ToastPrompt

2012-05-25 09:09:25

Windows Pho

2010-07-21 15:46:25

Windows Pho

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-04-16 17:02:50

Windows Pho概论

2013-07-30 11:18:37

Windows PhoWindows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2011-06-07 12:42:15

Windows Pho

2010-12-21 10:02:48

SilverlightWindows Pho

2010-11-01 14:49:20

Windows PhoWindows Pho

2010-06-21 15:39:59

Windows Pho
点赞
收藏

51CTO技术栈公众号