我不能同时同步位置和大小的 WPF 动画。
请查看我的代码,如果那里有问题,请告诉我。
谢谢!
void AnimatePlugin(double fromTop, double toTop, double fromLeft, double toLeft,
double fromH, double toH, double fromW, double toW, UIElement control)
{
Storyboard sb = new Storyboard();
#region Top
DoubleAnimation daTop = new DoubleAnimation();
daTop.From = fromTop;
daTop.To = toTop;
daTop.Duration = new Duration(TimeSpan.FromSeconds(1));
sb.Children.Add(daTop);
Storyboard.SetTargetProperty(daTop, new PropertyPath("(Canvas.Top)"));
Storyboard.SetTarget(daTop, control);
#endregion
#region Left
DoubleAnimation daLeft = new DoubleAnimation();
daLeft.From = fromLeft;
daLeft.To = toLeft;
daLeft.Duration = new Duration(TimeSpan.FromSeconds(1));
sb.Children.Add(daLeft);
Storyboard.SetTargetProperty(daLeft, new PropertyPath("(Canvas.Left)"));
Storyboard.SetTarget(daLeft, control);
#endregion
#region Heigh
DoubleAnimation daH = new DoubleAnimation();
daH.From = fromH;
daH.To = toH;
daH.Duration = new Duration(TimeSpan.FromSeconds(1));
sb.Children.Add(daH);
Storyboard.SetTargetProperty(daH, new PropertyPath("(Canvas.Height)"));
Storyboard.SetTarget(daH, control);
#endregion
#region Width
DoubleAnimation daW = new DoubleAnimation();
daW.From = fromW;
daW.To = toW;
daW.Duration = new Duration(TimeSpan.FromSeconds(1));
sb.Children.Add(daW);
Storyboard.SetTargetProperty(daW, new PropertyPath("(Canvas.Width)"));
Storyboard.SetTarget(daW, control);
#endregion
sb.Completed += (w, r) => { control.UpdateLayout(); };
sb.Begin();
}