tags:

views:

78

answers:

1

In Silverlight, I'm trying to draw a line on a Canvas by setting the LineGeometry element's EndPoint to the cursor position. In the Canvas' MouseMove event, I'm doing this:

line.EndPoint = e.GetPosition(this);

where "this" is the Canvas.

"line" is a LineGeometry element added to a GeometryGroup, and the GeometryGroup is added to a path object, which is added to the Canvas' Children collection.

The line does not show up on the canvas. What causes this?

A: 

This isn't an area that I understand very well, and I'm only answering because nobody else has answered yet :-). But I think the issue might be that the line's EndPoint is defined relative to its container (the GeometryGroup), but the Point structure returned by e.GetPosition(this) is relative to the containing control. You may need to apply a Transform to the e.GetPosition(this) to get the correct point. See here for more details on how transforms work.

Ken Smith