Search code examples
wpfgeometryshapesscaletransform

Adding shape at mousedown point on WPF canvas


I have a canvas with zoom (ScaleTransform). Now I have scaled the canvas by some arbitrary zoom value. I'm adding RectangleGeomtry at the MouseDown Point with every MouseDown event. But the strange thing is the Shape is getting added to the canvas with some +/-dx and +/-dy to the MouseDown Point.

Any leads on why this happening is much appreciated.


Solution

  • In a scaled canvas, you should get an inverse transform (Scale and Translate) of the point and then apply transform (Scale and Translate) after constructing geometry. It worked. I am not sure if that's the best way.