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工具来绘制三个表针,并放好位置。

 

 

四.增加动画效果

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

 

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

五.控制表针行为语句

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

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows 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-17 14:00:06

Windows PhoWindows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2013-04-16 17:02:50

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技术栈公众号