C# 当使用DoubleAnimation设置动画时,WPF控件将消失

C# 当使用DoubleAnimation设置动画时,WPF控件将消失,c#,wpf,xaml,animation,doubleanimation,C#,Wpf,Xaml,Animation,Doubleanimation,我有一个文本框(toAnimate)和一个按钮(toClick)。 当我点击按钮时,文本框消失了。 但它应该在X位置移动20个单位。 我做错了什么 //double left = Canvas.GetLeft(toAnimate); Returned wrong value. TranslateTransform tanl = new TranslateTransform(); Vector pos = VisualTreeHelper.GetOffset(toAnimate); double

我有一个文本框(toAnimate)和一个按钮(toClick)。 当我点击按钮时,文本框消失了。 但它应该在X位置移动20个单位。 我做错了什么

//double left = Canvas.GetLeft(toAnimate); Returned wrong value.
TranslateTransform tanl = new TranslateTransform();
Vector pos = VisualTreeHelper.GetOffset(toAnimate);
double left = pos.X;
toAnimate.RenderTransform = tanl;
DoubleAnimation doua = new DoubleAnimation((left + 20), left, TimeSpan.FromSeconds(3));
tanl.BeginAnimation(TranslateTransform.XProperty, doua);

在顶部有一行:Canvas.GetLeft(toAnimate)。似乎对返回的值不做任何处理?是否应该设置Canvas.Left而不是TranslateTransform.XProperty的动画?Canvas.LeftProperty不是right属性。