I am using the following code to get pixel coordinates of the mouse position.
private void canvas_MouseMove(object sender, MouseEventArgs e)
{
startPoint = e.GetPosition(this);
}
However, if the user uses the scroll bar to move down a bit then this code does not work. I get the wrong coordinates and the object does not get drawn under the mouse position. Any ideas what going on here?
What you’re doing should (more or less) work. You might have some problem with exactly which
MouseMoveevent you are listening to, though.Here is a sample app that demonstrates the desired behavior.
The XAML:
The code-behind:
The key here is I bound the
MouseMoveevent to theScrollViewer, and checked the position of theCanvas.