c# - How to get the new position of a moving shape in WPF -


i create ellipses seconds after program started ellipse myellipse = new ellipse(); move ellipses this

public void moveto(shape target, double newx, double newy, double oldx, double oldy)         {              translatetransform trans = new translatetransform();             target.rendertransform = trans;             doubleanimation anim1 = new doubleanimation(0, newy - oldy, timespan.fromseconds(5));             doubleanimation anim2 = new doubleanimation(0, newx - oldx, timespan.fromseconds(5));             trans.beginanimation(translatetransform.yproperty, anim1);             trans.beginanimation(translatetransform.xproperty, anim2);          } 

when within movement new position want new x , y position while moving , use timer x , y on time want when use canvas.getleft(name) returns nan , used point p = mellipse.translatepoint(new point(0, 0), canvasname); , returns initial position of ellipse not new 1

you current position of child of canvas calling canvas.getleft , canvas.gettop if animate canvas.left , canvas.top properties this:

public static void moveto(uielement target, double x, double y) {     var duration = timespan.fromseconds(5);     target.beginanimation(canvas.leftproperty, new doubleanimation(x, duration));     target.beginanimation(canvas.topproperty, new doubleanimation(y, duration)); } 

note have set initial values canvas.left , canvas.top properties, like

canvas.setleft(myellipse, 0); canvas.settop(myellipse, 0); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -