I've got what I consider a simple situation, but can't seem to figure out how to get it done. I'm very new to WPF and the Caliburn Micro framework. In my View, I have a Canvas and on this Canvas I have an Image. I want to write some mouse event handlers (MouseLeftButtonDown, MouseLeftButtonUp, and MouseMove) that are called when the cursor is inside the Image. I have successfully been able to create event handlers in the ViewModel, but I can't seem to figure out how to get the current cursor position inside the handlers. The MouseEventArgs.GetPosition requires a IInputElement as an argument...not sure how to get that.
Here's my XAML (view):
<Canvas x:Name="ImageCanvas" >
<Image Source="{Binding DataImage}"
x:Name="ContainerImage"
cal:Message.Attach=
"[Event MouseLeftButtonDown] = [Action MouseDown_Image($source, $eventArgs)];
[Event MouseLeftButtonUp] = [Action MouseUp_Image($source, $eventArgs)];
[Event MouseMove] = [Action MouseMove_Image($source, $eventArgs)]">
</Image>
</Canvas>
Here's my C# (viewmodel)
public void MouseDown_Image(object sender, MouseEventArgs e)
{
// How do I get cursor position here??
// convert to Image coordinates??
}
public void MouseUp_Image(object sender, MouseEventArgs e)
{
// How do I get cursor position here??
// convert to Image coordinates??
}
public void MouseMove_Image(object sender, MouseEventArgs e)
{
// How do I get cursor position here??
// convert to Image coordinates??
}
Once I do this, I'll need to convert the mouse coordinates to coordinates on the Image...but first things first.
Thanks!!