0

I am trying to make an image slide diagonally in windows phone 8 C#, i have tried some code, and gotten rid of an error i created - but when i doubletap the canvas, it is supposed to trigger the event, but nothing happens. Please take a look at my code:

        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();
    }

And also, something i dont understand. How can i set the target property of the StoryBoard, and not the one i created, two times? I added this piece of code to iron out an error, which created a new one

Erik
  • 799
  • 2
  • 15
  • 27
  • If you attach a debugger does the event fire ok? – geedubb Sep 25 '13 at 13:50
  • sorry, but i'm a bit new with visual studio, and this setup. How do i attach a debugger? Could you explain simply what it is? – Erik Sep 25 '13 at 14:00
  • It was just a weird problem, i changed the brush and some other stuff and suddenly it worked, i'm gonna check it out. – Erik Sep 25 '13 at 15:08
  • I did something like this and I found that using Expression Blend was extremely helpful. All you have to do is open Blend -> Open your project, create a timeline where you can animate and start using the propereties such as Skew etc and move the image. You're already using a Story Board so you must know how it works. Also, ensure that you're Double Tapping the canvas and not a control that's over the canvas. To make it easier, add that code to a button first and then test it out. – Subby Sep 25 '13 at 16:09
  • Thanks, i will check out doing it in blend, i got it working - suddenly it worked, weird - thanks though;) – Erik Sep 25 '13 at 16:33

0 Answers0