0

我正在尝试在 windows phone 8 C# 中对角滑动图像,我尝试了一些代码,并摆脱了我创建的错误 - 但是当我双击画布时,它应该触发事件,但没有任何反应。请看一下我的代码:

        private void Canvas_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        //The canvas was doubletapped

        //Create DoubleAnimation for x value
        DoubleAnimation movedefenderxpositionAnimation = new DoubleAnimation();
        movedefenderxpositionAnimation.From = 0;
        movedefenderxpositionAnimation.To = 30;
        movedefenderxpositionAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
        movedefenderxpositionAnimation.AutoReverse = false;

        //Create DoubleAnimation for y value
        DoubleAnimation movedefenderypositionAnimation = new DoubleAnimation();
        movedefenderypositionAnimation.From = 0;
        movedefenderypositionAnimation.To = 15;
        movedefenderypositionAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
        movedefenderypositionAnimation.AutoReverse = false;

        //Create StoryBoard
        Storyboard movedefenderxpositionSB = new Storyboard();
        movedefenderxpositionSB.Children.Add(movedefenderxpositionAnimation);

        Storyboard movedefenderypositionSB = new Storyboard();
        movedefenderypositionSB.Children.Add(movedefenderypositionAnimation);

        //Set the timespan
        movedefenderxpositionSB.Duration = new Duration(TimeSpan.FromSeconds(1));
        movedefenderypositionSB.Duration = new Duration(TimeSpan.FromSeconds(1));

        //Set the target
        Storyboard.SetTarget(movedefenderxpositionAnimation, squaddefender1);
        Storyboard.SetTarget(movedefenderypositionAnimation, squaddefender1);

        //Set the target property
        Storyboard.SetTargetProperty(movedefenderxpositionAnimation, new PropertyPath("(Canvas.Left)"));
        Storyboard.SetTargetProperty(movedefenderypositionAnimation, new PropertyPath("(Canvas.Top)"));

        //Start the animation
        movedefenderxpositionSB.Begin();
        movedefenderypositionSB.Begin();
    }

还有,我不明白的东西。如何设置 StoryBoard 的 target 属性,而不是我创建的那个,两次?我添加了这段代码来解决一个错误,它创建了一个新的

4

0 回答 0