zoukankan      html  css  js  c++  java
  • 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         }
  • 相关阅读:
    web前端的面试真题
    web前端面试真题! 面试的经历和回答只做参考1
    web前端面试真题! 面试的经历和回答只做参考
    html面试资料
    angluar.js的核心介绍
    解决 Chrome支持小于12px 的文字
    div居中效果出现的问题和解决方法
    li和li之间的bug解决方法
    前端面试题笔试考题和答案
    html5新增的标签和使用的方法
  • 原文地址:https://www.cnblogs.com/XzcBlog/p/3831446.html
Copyright © 2011-2022 走看看