1

Is there any way to detect a right click event from a mouse when using Xamarin for a UWP app? There does not seem to be any way to access mouse events except as they simulate touch events.

asked Oct 6, 2019 at 22:28
0

1 Answer 1

1

If this is just a pure UWP app there is a UIElement.PointerPressed Event you can subscribe to.

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.IsRightButtonPressed)
 {
 // Do something
 }
 // Prevent most handlers along the event route from handling the same event again.
 e.Handled = true;
 }
}

Check out the docs for more info.

answered Oct 6, 2019 at 23:09
Sign up to request clarification or add additional context in comments.

4 Comments

This looks quite promising, thanks for the response. Now let's say that I have a Xamarin control (e.g. Xamarin.Forms.Grid), how do I get the underlying UIElement for that control in the case where it is a UWP app. Note, I am not looking for a cross platform solution, only one that will works with UWP apps.
The easiest way might be to use the native control directly in Xaml/C#, especially if this is intended only as a UWP Forms app. It's that or you'll have to create your own custom renderer for that specific control(s).
The app is cross platform, but when the user is using the Windows version, I want to add some mouse functionality that would not be available on the other platforms. I will look into the custom renderer. Thanks again.
Well that was a lot of hoops to jump through just to be able to tell if the user clicked with the right mouse button but it works. Thanks for your help.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.