Getting mouse position in MouseDown event
Posted: 07 Apr 2019, 03:18
Hi,
I have a very simple UserControl on which I apply in the XAML, and in the ConnectEvent of my root code-behind:
and then:
I'm getting:
However, when I handle the MouseDown event directly in the MyUserControl code, eg,
It works as expected and I'm getting (for example)
What am I doing wrong in the first example? Thanks!
I have a very simple UserControl on which I apply
Code: Select all
MouseDown="OnMouseDownMyUserControl"Code: Select all
if (eventName == "MouseDown" && handlerName == "OnMouseDownMyUserControl"){
((MyUserControl)source).MouseDown += OnMouseDownMyUserControl;
return true;
}
Code: Select all
void OnMouseDownMyUserControl(object sender, MouseButtonEventArgs args)
{
var _offset = args.GetPosition(sender as MyUserControl);
Console.WriteLine($"X: {_offset.X} Y: {_offset.Y}");
}
Code: Select all
X: 4.591495E-41 Y: 1.277719E-21Code: Select all
public class MyUserControl: UserControl
{
public MyUserControl()
{
this.MouseDown += (s, e) => {
var _offset = e.GetPosition(s as Blargh);
Console.WriteLine($"X: {_offset.X} Y: {_offset.Y}");
};
}
}Code: Select all
X: 89 Y: 306