2012-12-26 94 views
3

這裏是什麼樣子: http://screencast.com/t/4cd1yQJReXtWPF動畫沿着正確的路徑,但它關在空間

的小船圖像是假設跟着你出去圖表爲它的路徑。它確實有效 - 它遵循路徑,但是它從錯誤的地方開始。我無法弄清楚我的動畫有什麼問題,而且我現在已經多次閱讀了代碼。應用程序的XAML是非常簡單的都是含有內 帆布NAME =「Canvas1」背景中的元素=「黑」

,這畫布是 窗口

及以下的子元素是代碼,做動畫。我知道一個事實,即我餵它的線是正確的。這只是他們的參考點被搞砸了。它應該是Canvas1,但它不是。

  NameScope.SetNameScope(this, new NameScope()); 

      MatrixTransform buttonMatrixTransform = new MatrixTransform(); 
      ship1.RenderTransform = buttonMatrixTransform; 

      this.RegisterName("ButtonMatrixTransform", buttonMatrixTransform); 

      PathGeometry animationPath = new PathGeometry(); 
      PathFigure pFigure = new PathFigure(); 
      pFigure.StartPoint = new Point(pathnodes.ElementAt<Line>(0).X1, pathnodes.ElementAt<Line>(0).Y1); 

      PolyLineSegment ls = new PolyLineSegment(); 

      foreach (Line l in pathnodes) 
      { 
       ls.Points.Add(new Point(l.X1, l.Y1)); 
       ls.Points.Add(new Point(l.X2, l.Y2)); 
      } 

      pFigure.Segments.Add(ls);  
      animationPath.Figures.Add(pFigure); 

      animationPath.Freeze(); 

      MatrixAnimationUsingPath matrixAnimation = 
       new MatrixAnimationUsingPath(); 

      matrixAnimation.IsOffsetCumulative = false; 

      matrixAnimation.PathGeometry = animationPath; 
      matrixAnimation.Duration = TimeSpan.FromSeconds(5); 
      matrixAnimation.DoesRotateWithTangent = true; 

      Storyboard.SetTargetName(matrixAnimation, "ButtonMatrixTransform"); 
      Storyboard.SetTargetProperty(matrixAnimation, 
       new PropertyPath(MatrixTransform.MatrixProperty)); 

      Storyboard pathAnimationStoryboard = new Storyboard(); 
      pathAnimationStoryboard.Children.Add(matrixAnimation); 

      pathAnimationStoryboard.Begin(this); 

謝謝!

回答

0

我看不到你的視頻:O(但是,它可能與RenderTransformOrigin沒有設置嗎?通常當我進行轉換時,我將RTO設置爲0.5,0.5,以便原點位於物體的中心。