Question: I have a control in WPF (which is a custom control containing a circle).

And I need to move it every 60ms.

I have an array of "Position" (Class with 2 attributes : X and Y) and I do this to move it :

```
timer_tick()
{
  myControl.Margin = new Thickness { Left = MyArray[i].X, Top = MyArray[i].Y};
  i++;
}

```

with a global variable.

But can I do it in a better way ? Using something like : 

```
public static void MoveTo(this Image target, double newX, double newY)
{
    var top = Canvas.GetTop(target);
    var left = Canvas.GetLeft(target);
    TranslateTransform trans = new TranslateTransform();
    target.RenderTransform = trans;
    DoubleAnimation anim1 = new DoubleAnimation(top, newY - top, TimeSpan.FromMilliseconds(60));
    DoubleAnimation anim2 = new DoubleAnimation(left, newX - left, TimeSpan.FromMilliseconds(60));
    trans.BeginAnimation(TranslateTransform.XProperty,anim1);
    trans.BeginAnimation(TranslateTransform.YProperty,anim2);
}

```

in every tick ?

Thank you

Answer: 
Very close. But there is no need to call this in a timer. Let the animation do the work; that is what it is for. Just set the animations to go from the origin to the destination in a timespan for the desired speed. You can always interrupt the animation at any point if you need it to end early.
Someone else already posted the best way, which is to use an animation, so here's a different way that's less "good" but probably works ok.

If you're using variables like that indexer "i" (careful about calling it global - be specific about its scope) then why not make another one?

At the class level, create a variable...

```
Thickness awful_marg_variable;

```

And in your initializer, initialize it and assign the reference to the control's Margin:

```
awful_marg_variable = new Thickness { Left = MyArray[0].X, Top = MyArray[0].Y};
myControl.Margin = awful_marg_variable;

```

And then in your timer tick procedure, you can just manipulate that variable...

```
awful_marg_variable.Left = MyArray[i].X;
awful_marg_variable.Top = MyArray[i].Y;

```

Finally, you can revel in the horrible thing you've just done, or whatever. Never do this in large quantities. Some people would say never do this ever. But sometimes you just gotta get work done and this is one more way to do it.