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
?有没有更好的方法在不使用边距的情况下为图像设置动画?