c# - Newbie WPF: Does the animation remove the attached property? -
i trying learn wpf , animations. have simple program allows user move ellipse using mouse. when mouse button released, ellipse's position animated towards top of screen.
this works fine first time grab ellipse. second time grab ellipse can not change it's y-position anymore (but can still change x-position). does animation somehow remove attached canvas.top
property? how can correct problem?
here code starts animation (located in mouseup handler)
duration duration = new duration(timespan.fromseconds(5.0*oldy/1000)); doubleanimation anim = new doubleanimation(oldy, 0, duration); // move top of canvas _shapeselected.beginanimation(canvas.topproperty, anim);
and here mouse move handler
private void canvas_mousemove_1(object sender, mouseeventargs e) { if (_shapeselected != null) { point pt = e.getposition(thecanvas); canvas.setleft(_shapeselected, (pt.x-_posofmouseonhit.x) + _posofshapeonhit.x ); canvas.settop(_shapeselected, (pt.y-_posofmouseonhit.y) + _posofshapeonhit.y ); } }
set animation's fillbehavior
stop
. property reverts current local value when animation has finished, have set local value after animation has started.
var anim = new doubleanimation(oldy, 0, duration, fillbehavior.stop); _shapeselected.beginanimation(canvas.topproperty, anim); canvas.settop(_shapeselected, 0);
Comments
Post a Comment