Reputation: 51
I am creating a silverlight application which will allow you to click at two places on the screen and will draw an ellipse whose major axis starts and ends at the click locations. The clickable area is a Silverlight Grid control. Currently:
When you first click, I am:
As you move the mouse, I am:
So far, so good. The ellipse is displayed, and its length and angle of rotation follow the mouse as it moves.
However, the major axis of the ellipse is offset from the click point. How do I position the Ellipse so its major axis starts at the click point and ends at the current mouse position?
Upvotes: 3
Views: 2281
Reputation: 51
The answer turned out to be:
Don't use System.Windows.Shapes.Ellipse
. Instead use System.Windows.Shapes.Path
and embed an EllipseGeometry
in it.
Also set the Path.RenderTransform
to a RotateTransform
.
Don't set Width
or Height
or Stretch
on the Path
. Instead set the Center
, RadiusX
, and RadiusY
of the EllipseGeometry
.
Finally, set the RotateTransform.Angle
to the angle of intersection of the Ellipse
major-axis and the X-axis (the ArcTan
of the major-axis slope). Also set RotateTransform.CenterX
and CenterY
to the EllipseGeometry
Center
.
Upvotes: 2
Reputation: 78
May be it's a good idea to use Canvas instead of grid for your application, than you will be able to set up shapes coordianates directly.
Upvotes: 0
Reputation: 16011
If I had to guess (code would help), I would think that you could add padding from the difference of the beginning click point to the left side of the grid, which should help move it over by the offset.
Upvotes: 0