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         }
  • 相关阅读:
    让SiteMapDataSource能选择特定的SiteMap文件
    程序员之路──如何学习C语言(转载)
    Sql Server 2005 Express使用命令工具无法连接问题
    移远公司 NBIoT模块AT指令详细解释
    Excel自动化技术
    解析HTTP报文头
    SOAP报文下发
    双缓冲队列,生产者消费者模式
    夸孩子少用“你真棒”,教你如何夸孩子
    C++面试题相关
  • 原文地址:https://www.cnblogs.com/XzcBlog/p/3831446.html
Copyright © 2011-2022 走看看