tags:

views:

209

answers:

1

I am new to WPF.

I want to draw a small circle on Canvas when I click mouse and be able to drag it around smoothly.

How can I accomplish this?

+3  A: 

"whatever it is" matters because placement of elements in WPF is highly dependent on the parent container. It's easy to move something 20px to the right inside a Canvas (just add to Canvas.Left), but it's much harder to do so in a Grid (you have to deal with Column, ColumnSpan and Margin).

There's a code project article describing how to drag elements inside a Canvas: Dragging Elements in a Canvas

If you want to move just that circle and not other controls in an existing Canvas/Grid; I suggest you use a DragCanvas (from the article) as an overlay over the normal Canvas/Grid.

As for the 'draw a circle' part: just use an Ellipse as element inside the DragCanvas.

Daniel
Ok. I am using Canvas and done with drawing but dragging is still a problem. Can you provide small code snippet?
TheMachineCharmer
+1 for the code project link.
Drew Noakes