Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在X和Y方向上移动对象动画_C#_Wpf_Xaml - Fatal编程技术网

C# 在X和Y方向上移动对象动画

C# 在X和Y方向上移动对象动画,c#,wpf,xaml,C#,Wpf,Xaml,我已经为X中的移动对象创建了动画,但如何同时添加Y TranslateTransform trans = new TranslateTransform(); Pointer.RenderTransform = trans; DoubleAnimation anim2 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325)); anim2.EasingFunction = new SineEase { EasingMode = Ea

我已经为X中的移动对象创建了动画,但如何同时添加Y

TranslateTransform trans = new TranslateTransform();
Pointer.RenderTransform = trans;
DoubleAnimation anim2 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim2.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim2.Completed += new EventHandler(myanim_Completed);
trans.BeginAnimation(TranslateTransform.XProperty, anim2);
找到了答案:

        TranslateTransform trans = new TranslateTransform();
        Pointer.RenderTransform = trans;
        DoubleAnimation animX = new DoubleAnimation(0, 750, TimeSpan.FromMilliseconds(325));
        DoubleAnimation animY = new DoubleAnimation(0, 100, TimeSpan.FromMilliseconds(325));

        animX.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
        animY.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };

        animX.Completed += new EventHandler(myanim_Completed);
        trans.BeginAnimation(TranslateTransform.XProperty, animX);
        trans.BeginAnimation(TranslateTransform.YProperty, animY);
使用并添加两个动画作为子动画:

Storyboard storyBoard = new Storyboard
                    { Duration = new Duration(TimeSpan.FromMilliseconds(325)) };

DoubleAnimation anim2 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim2.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim2.Completed += new EventHandler(myanim_Completed);
Storyboard.SetTarget(anim2, trans);
Storyboard.SetTargetProperty(anim2, new PropertyPath(TranslateTransform.XProperty));

DoubleAnimation anim1 = new DoubleAnimation(1, 500, TimeSpan.FromMilliseconds(325));
anim1.EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut };
anim1.Completed += new EventHandler(myanim_Completed);
Storyboard.SetTarget(anim1, trans);
Storyboard.SetTargetProperty(anim1, new PropertyPath(TranslateTransform.YProperty));

storyBoard.Children.Add(anim2);
storyBoard.Children.Add(anim1);

storyBoard.Begin();

将动画放在情节串连板中,而不是手动启动动画。您是打算用代码执行此任务,还是XAML会这样做?我问是因为这是我做这件事的唯一方式。只有在代码中,对不起。。。