1
votes

I am currently trying to transport my WPF Control to UWP and am stuck at the PointerMoved event. While I was able to check the state of a Mousebutton in WPF and execute my code only if the state was true, I can't figure out the equivalent in UWP.

What I have in WPF

private void MyControl_MouseMove(object sender, MouseEventArgs e)
{
  if (Mouse.LeftButton == MouseButtonState.Pressed)
    { 
       //...
    }
}

What I want in UWP

private void MyControl_PointerMoved(object sender, PointerRoutedEventArgs e)
{
   if("PointerIsBeingPressed")
     {
         //...
     }
}

Every answer or hint to do things differently is appreciated!

1
@Chrille hint worked immediately, thanks! - Nigel-Lee

1 Answers

3
votes

Microsoft provides an example in the documentation:

private void Target_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    Windows.UI.Xaml.Input.Pointer ptr = e.Pointer;

    if (ptr.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
    {      
        Windows.UI.Input.PointerPoint ptrPt = e.GetCurrentPoint(Target);
        if (ptrPt.Properties.IsLeftButtonPressed)
        {
            //Handle button press
        }        
    }
}