2

So I have a canvas and a Ellipse on it . And call a method to mote the Ellipse around like so

public void moveElipse1ToCoordinate(Point point)
    {
        Action action = () =>
        {
           TranslateTransform moveTo = new TranslateTransform();
            moveTo.X = point.X;  
            moveTo.Y = point.Y;
            StimulyEllipse1.RenderTransform = moveTo;
        };
        Dispatcher.BeginInvoke(action);
    }

And I use this function in a for loop .

for(int i=0 ; i<=1000; i++)
moveElipse1ToCoordinate(new Point(i,i)

Both X and Y coordinates are constantly between 0 and 1000 , the size of the canvas . Yet the Ellipse is not shown at all .

What am I missing from this call ?

Matt Mills
  • 8,692
  • 6
  • 40
  • 64
Iustinian Olaru
  • 1,231
  • 1
  • 13
  • 33

1 Answers1

2

If you want it to move smoothly, as an animation, you'll need to use the animation classes specifically. The UI won't update until the loop has completed (and with an X,Y of the size of the canvas, the ellipse would appear below and to the right of the total canvas).

pete the pagan-gerbil
  • 3,136
  • 2
  • 28
  • 49
  • Ok so I made it so that I am using the DoubleAnimation class and it works. My problem now is that I currently have no way of obtaining the depencency value of the Ellipse to apply my animation to . It's position is first set up with Canvas.SetTop , however thats not the ellipses property so that I can use it in the BeginAnimation arguments . Could you suggest what i could use to refer to the X and Y position of that UI Element relative to it's parent ? (in this case a Canvas ) ? – Iustinian Olaru Aug 25 '15 at 14:39
  • Code , I am looking to move the UIElement with coordinates recieved from another function . It will move in 2D on X and Y axis and will be user controller by a device so it should be as smooth as possible . – Iustinian Olaru Aug 25 '15 at 16:26
  • `myEllipse.GetValue(Canvas.TopProperty)` - does this help? Otherwise, you might want to ask a new question on here. – pete the pagan-gerbil Aug 25 '15 at 21:26
  • Unfortunatelly I tryed this but it tells me that it can't convert from object to dependency value. I'll try and ask a separate question. – Iustinian Olaru Aug 26 '15 at 07:44