0

Image我正在尝试移动到新位置的 1x1 网格上有一个 WPF 。我正在使用以下代码:

public void AnimateImage(int seatNum, int cardNum)
{
   // This method animates dealing a cardback image to the specified seat.
   //
   Point[][,] Margins;
   Margins = CardMargins; // CardMargins contains the positions to where the cards should end up after being moved.
   Image CardbackImage1 = CardbackImages[seatNum, cardNum];
   // Specify the starting position of the image.
   CardbackImage1.Margin = new Thickness(DealerStartX, DealerStartY, 0, 0);
   CardsGrid.Children.Insert(seatNum, CardbackImage1);
   // Note that if instead of specifying the starting point, the to-point is specified instead,
   // and a return inserted at this point - it displays the card in the correct location.
   TranslateTransform trans = new TranslateTransform();
   CardbackImage1.RenderTransform = trans;
   double ToPosX = Margins[NumSeats][seatNum, cardNum].X;
   double ToPosY = Margins[NumSeats][seatNum, cardNum].Y;
   // DoubleAnimation CardsAnimX = new DoubleAnimation(DealerStartX, 65, TimeSpan.FromSeconds(DealAnimateTime));
   DoubleAnimation CardsAnimX = new DoubleAnimation(DealerStartX, ToPosX, TimeSpan.FromSeconds(DealAnimateTime));
   // DoubleAnimation CardsAnimY = new DoubleAnimation(DealerStartY, DealerStartY - 50, TimeSpan.FromSeconds(DealAnimateTime));
   DoubleAnimation CardsAnimY = new DoubleAnimation(DealerStartY, ToPosY, TimeSpan.FromSeconds(DealAnimateTime));
   trans.BeginAnimation(TranslateTransform.XProperty, CardsAnimX);
   trans.BeginAnimation(TranslateTransform.YProperty, CardsAnimY);
}

CardMargins数组用于保存卡片应该结束的位置。卡片动画,但问题是卡片没有在正确的位置结束。我已经验证了数组内部的值以及CardMargins数组的索引是正确的。我怀疑该TranslateTransform方法要么使用不同类型的坐标,要么使用不同的坐标系。

可以将边距用作动画属性,如果可以,是否需要使用任何类型的转换才能将其与 一起使用TranslateTransform?有没有更好的方法在不使用边距的情况下为图像设置动画?

4

1 回答 1

1

Margin使用动画属性本身可能更简单ThicknessAnimation

例子:

ThicknessAnimation CardAni = new ThicknessAnimation(StartMargin, EndMargin, TimeSpan.FromSeconds(DealAnimateTime));
CardbackImage1.BeginAnimation(Image.MarginProperty, CardAni);
于 2013-05-29T01:12:31.373 回答