private void Window_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
{
DoubleAnimation rightAnimation = new DoubleAnimation();
rightAnimation.Duration = TimeSpan.FromSeconds(2);
rightAnimation.From = 0;
rightAnimation.To = 200;
Storyboard.SetTarget(rightAnimation , rect1);
Storyboard.SetTargetProperty(rightAnimation, new PropertyPath("(0).(1)", new DependencyProperty[]{UIElement.RenderTransformProperty, TranslateTransform.XProperty}));
Storyboard sb = new Storyboard();
sb.AccelerationRatio = 0.8;
sb.Children.Add(rightAnimation);
sb.Begin();
}
我想将rect1加速到右边..当我运行它时没有任何反应。
答案 0 :(得分:1)
您可以使用TransformGroup
为所有转换类型设置动画。
DoubleAnimation rightAnimation = new DoubleAnimation();
rightAnimation.Duration = TimeSpan.FromSeconds(2);
rightAnimation.From = 0;
rightAnimation.To = 200;
TransformGroup transGroup = new TransformGroup();
transGroup.Children.Add(new TranslateTransform());
rect1.RenderTransform = transGroup;
Storyboard.SetTarget(rightAnimation, rect1);
Storyboard.SetTargetProperty(rightAnimation, new PropertyPath("RenderTransform.Children[0].X"));
Storyboard sb = new Storyboard();
sb.AccelerationRatio = 0.8;
sb.Children.Add(rightAnimation);
sb.Begin();