我有使我对动画有一个DoubleAnimation是做对象的方法:不能够与代码动画TranslateTransform.XProperty
public void animDouble(DependencyObject target, DependencyProperty property, double to, TimeSpan duration, double? from = null, TimeSpan? beginTime = null, IEasingFunction e = null)
{
DoubleAnimation animation = new DoubleAnimation();
animation.To = to;
if (beginTime == null)
beginTime = TimeSpan.FromSeconds(0);
if (from != null)
animation.From = from;
animation.BeginTime = beginTime;
animation.Duration = duration;
if (e != null)
animation.EasingFunction = e;
//start animating
Storyboard.SetTarget(animation, target); // what object will be animated?
Storyboard.SetTargetProperty(animation, new PropertyPath(property)); // what property will be animated
Storyboard sb = new Storyboard();
sb.Children.Add(animation);
sb.Begin();
}
,所以如果我呼吁BR1例如,我寄宿生想动画它的高度,我会调用该方法为:
animDouble(br1, FrameworkElement.HeightProperty, 150, TimeSpan.FromSeconds(5));
,如果我想动画它的宽度,我会做的事:
animDouble(br1, FrameworkElement.WidthProperty, 150, TimeSpan.FromSeconds(5));
我也可以用相同的方法动画它的可见性。
由于某些原因,我无法为其x属性进行动画制作,以便将其沿x轴或y轴进行转换。当我将该方法称为:
a.animDouble(br1, TranslateTransform.XProperty, 150, TimeSpan.FromSeconds(5));
寄宿生不动画。我没有任何错误。
请不要只打你的标题“C#”。这就是标签的用途。 –