c# uwp pointer position

Viewed 8769

In UWP I am trying to get position of pointer.

I have managed to do it with next Event:

    private void Grid_PointerMoved(object sender, PointerRoutedEventArgs e)
    {
        PointerPoint point = e.GetCurrentPoint(mainGrid);
        var x = point.Position.X;
        var y = point.Position.Y;
    }

And with this way it will be fired all the time. So, I needed some property to get that position. I have found this:

var pointerPosition = Windows.UI.Core.CoreWindow.GetForCurrentThread().PointerPosition;

But it doesn't always return correct position.

Any other property to get current mouse location?

3 Answers

This works for me at my canvas:

 var x = e.GetCurrentPoint(canBackArea).Position.X;
 var y = e.GetCurrentPoint(canBackArea).Position.Y;
Related