Windows Phone开发(38):动画之PointAnimation

移动开发
以LineGeometry作为动画的目标对象,通过对StartPoint属性和EndPoint属性进行动画来让直线(其实是线段)动起来。BezierSegment的三个点进行动画,即使贝塞尔曲线“游动”起来。

PointAnimation也是很简单的,与前面说到的两个Animation是差不多的,属性也是一样的,如By、From、To,不同的是,PointAnimation是目标值从一点到另一个点。

我有理由相信,大家一定懂的,所以,我不多介绍了,给两个例了热一下身就行了。

例一,让直线动起来。

这个例子,以LineGeometry作为动画的目标对象,通过对StartPoint属性和EndPoint属性进行动画来让直线(其实是线段)动起来。

  1. <Grid>   
  2.     <Path HorizontalAlignment="Stretch" VerticalAlignment="Stretch"   
  3.           Stroke="Orange" StrokeThickness="6">   
  4.         <Path.Data>   
  5.             <LineGeometry x:Name="lg" StartPoint="25,32" EndPoint="185,97"/>   
  6.         </Path.Data>   
  7.     </Path>   
  8.     <Grid.Resources>   
  9.         <Storyboard x:Name="std" RepeatBehavior="Forever" AutoReverse="True">   
  10.             <PointAnimation Duration="0:0:5"   
  11.                             Storyboard.TargetName="lg"   
  12. yboard.TargetProperty="StartPoint"   
  13.                             To="20,375"/>   
  14.             <PointAnimation Duration="0:0:5"   
  15.                             Storyboard.TargetName="lg"   
  16. yboard.TargetProperty="EndPoint"   
  17.                             To="407,490"/>   
  18.         </Storyboard>   
  19.     </Grid.Resources>   
  20. </Grid>   

记得了,在页面的Loaded事件中激活动画。

  1. // 构造函数   
  2. public MainPage()   
  3. {   
  4.     InitializeComponent();   
  5.    
  6.     this.Loaded += (sender, e) =>   
  7.         {   
  8.             this.std.Begin();   
  9.         };   
  10. }  

例二,对曲线进行动画。

本例对BezierSegment的三个点进行动画,即使贝塞尔曲线“游动”起来。

  1.     <Grid>   
  2.         <Path HorizontalAlignment="Stretch" VerticalAlignment="Stretch"   
  3.               Stroke="LightGreen" StrokeThickness="12">   
  4.             <Path.Data>   
  5.                 <PathGeometry>   
  6.                     <PathFigure StartPoint="180,35">   
  7.                         <BezierSegment x:Name="pbm"    
  8.                                        Point1="28,180"   
  9.                                        Point2="200,270"   
  10.                                        Point3="412,700"/>   
  11.                     </PathFigure>   
  12.                 </PathGeometry>   
  13.             </Path.Data>   
  14.         </Path>   
  15.         <Grid.Resources>   
  16.             <Storyboard x:Name="std" RepeatBehavior="Forever" AutoReverse="True">   
  17.                 <PointAnimation Duration="0:0:3"   
  18.                                 Storyboard.TargetName="pbm"   
  19. Storyboard.TargetProperty="Point1"   
  20.                                 From="27,162" To="415,145"/>   
  21.                 <PointAnimation Duration="0:0:3"   
  22.                                 Storyboard.TargetName="pbm"   
  23. Storyboard.TargetProperty="Point2"   
  24.                                 To="600,400"/>   
  25.                 <PointAnimation Duration="0:0:3"   
  26.                                 Storyboard.TargetName="pbm"   
  27. Storyboard.TargetProperty="Point3"   
  28.                                 To="10,700"/>   
  29.             </Storyboard>   
  30.         </Grid.Resources>   
  31.     </Grid>   

后台代码就是在Loaded事件中激活动画,这个大家应该会了。

好了,这节课就这样很轻松地过了。

责任编辑:闫佳明 来源: oschina
相关推荐

2013-04-24 13:19:06

Windows Pho动画DoubleAni

2013-04-24 13:31:59

Windows Pho动画之ColorAni

2013-04-25 11:25:38

Windows PhoWindows Pho

2013-07-31 13:13:50

Windows PhoMVVM模式

2013-04-19 17:11:02

Windows PhoWindows Pho

2013-04-23 16:55:15

Windows Pho路径之其它Geomet

2013-07-31 13:36:07

Windows PhoVS调试技巧Windows Pho

2013-04-24 13:51:48

Windows PhoWindows Pho

2013-04-24 14:52:53

Windows PhoWindows Pho

2013-04-24 15:28:02

Windows PhoWindows Pho

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows 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

2010-08-06 15:44:28

Windows PhoWindows PhoSilverlight

2010-04-08 17:40:23

Windows Pho

2013-04-17 14:47:19

Windows PhoWindows Pho
点赞
收藏

51CTO技术栈公众号