我无法同时同步位置和大小的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();
}发布于 2012-08-24 22:37:31
只有Canvas.Left和Canvas.Top是附加属性...(并且您使用括号正确地指定了它们)。
然而,“宽度”和“高度”不是附加属性,它们是使用PropertyPath("Width")和PropertyPath("Height")的FrameworkElement......just的基本属性
与使用字符串指定属性的路径不同,您可以使用采用DependencyProperty type.....so的PropertyPath,并使用PropertyPath(Canvas.TopProperty)、PropertyPath(Canvas.LeftProperty)、PropertyPath(Canvas.WidthProperty)、PropertyPath(Canvas.HeightProperty)。
这样,您就不需要为PropertyPath字符串使用正确的语法而烦恼,这取决于是否附加了属性。
https://stackoverflow.com/questions/12111287
复制相似问题