PathAnimation

本文介绍如何使用Blend制作PathAnimation,并探讨了如何利用动态PathGeometry实现更灵活的动画效果。通过代码示例,展示了如何设置PathAnimation的关键属性,包括读取PathGeometry数据、设置动画时长及旋转方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文: PathAnimation

使用Blend制作PathAnimation

1:选中Path转换为运动路径

2:选择目标对象

 

PathAnimation使用动态的Path

PathAnimation动画在播放的时候,PahtGeometry是已经确定的,不会改变,不会实时的根据Path的改变动画进行调整,所以是不能进行绑定

只有在每一次需要播放动画之前读取相关的Path的Data,读取当前的PathGeometry然后开始动画

 1    <Path x:Name="path" Stroke="DarkGray" StrokeThickness="3">
 2             <Path.Data>
 3                 <PathGeometry>
 4                     <PathFigure 
 5                         StartPoint="{Binding Center, ElementName=ptStart}">
 6                         <BezierSegment 
 7                             Point1="{Binding Center, ElementName=ptCtrl1}"
 8                             Point2="{Binding Center, ElementName=ptCtrl2}"
 9                             Point3="{Binding Center, ElementName=ptEnd}"/>
10                     </PathFigure>
11                 </PathGeometry>
12             </Path.Data>
13         </Path>

 

 1  private void Button_Click(object sender, RoutedEventArgs e)
 2         {
 3             Canvas.SetLeft(this.truck, -this.truck.ActualWidth / 2);
 4             Canvas.SetTop(this.truck, -this.truck.ActualHeight / 2);
 5             this.truck.RenderTransformOrigin = new Point(0.5, 0.5);
 6 
 7             MatrixTransform matrix = new MatrixTransform();
 8             this.truck.RenderTransform = matrix;
 9 
10             NameScope.SetNameScope(this, new NameScope());
11             this.RegisterName("matrix", matrix);
12 
13             MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();
14             matrixAnimation.PathGeometry = this.path.Data.GetFlattenedPathGeometry();
15             matrixAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
16 
17             //matrixAnimation.AutoReverse = true;   //重复
18             //matrixAnimation.IsOffsetCumulative = !matrixAnimation.AutoReverse;
19             //matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;
20             matrixAnimation.DoesRotateWithTangent = false;   //旋转
21 
22             Storyboard story = new Storyboard();
23             story.Children.Add(matrixAnimation);
24             Storyboard.SetTargetName(matrixAnimation, "matrix");
25             Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));
26             story.Begin(this);
27         }

 

posted on 2018-08-14 10:08 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/9472888.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值