c# - How to: Drag and Drop movement in Windows 8 apps? -
i wanted make simple matching game better understanding of movement, in have outline of shape , shape itself. drag shape on outline , release have snap place. sounded simple. able move shapes using manipulationdelta events reason unable of drag events fire (dragover, dragenter, drop). have read on these events perhaps understanding flawed. event looking in order know when 1 shape dragged on another?
xaml
<canvas name="drawcanvas"> <ellipse name="shape1" fill="steelblue" height="200" width="200" manipulationmode="all" allowdrop="true" dragover="shape1_dragover" dragenter="shape2_dragenter" drop="shape1_drop"/> <ellipse name="shape2" height="209" width="209" stroke="steelblue" strokethickness="5" allowdrop="true" canvas.left="594" canvas.top="96" /> </canvas> i've tried every combination of dragover, dragenter, drop events on shape1 , shape2 never seem fire. these events not work shapes? or possibly don't work when using manipulationdelta movement?
thanks, appreciate or direction on this.
the answer bounds of canvas, size of shape , x,y. can derive 4 points around (topleft, topright, bottomleft, bottomright). when point exceeds boundary in manipulationdelta event set instead boundary. keeps shape "in bounds".
translation.x = e.delta.translation.x; translation.y = e.delta.translation.y // since checking left point subtract shapes width canvas right // bounds. if x greater set instead maximum bound. if (translation.x > (canvasright - shape.width)) translation.x = canvasright - shape.width; /// same top. if y less canvas top set instead right @ boundary. if (translation.y < canvastop) translation.y = canvastop; // same bottom , left it possible using shapes center may provide advantages depending on functionality implement. when using center calculation top or bottom of shape half of height, left , right half of width.
Comments
Post a Comment