0

I'm trying to create a simple uwp app where I require to display a context menu, if user right clicks on non-touch device and if user holds on touch screen device. I'm using righttapped event which works perfectly on my desktop. The other side, I use holding event which should be triggered when screen is long pressed but it doesn't work(on touch screen mobile).

private void Webview_Holding(object sender, HoldingRoutedEventArgs e)
    {
        Webview.ContextFlyout.ShowAt(sender as FrameworkElement);
    }

Do I need to use some other event for showing context menu, if yes then which one?

killerthawne
  • 115
  • 1
  • 12

1 Answers1

2

You should use RightTapped event for both touch and non-touch devices as I answered here. However, WebView does not support all of the touch or keyboard events.

Remarks section of MSDN for WebView control:

As indicated in the Events table, WebView doesn’t support most of the user input events inherited from UIElement, such as KeyDown, KeyUp, and PointerPressed. A common workaround is to use InvokeScriptAsync with the JavaScript eval function to use the HTML event handlers, and to use window.external.notify from the HTML event handler to notify the application using WebView.ScriptNotify.

Mehrzad Chehraz
  • 5,092
  • 2
  • 17
  • 28
  • I know the usage of RightTapped very well and I've used it too. But as I mentioned in my question, my problem is with Holding_event which is triggered in case of touch screen devices. – killerthawne Jun 04 '17 at 16:32
  • @VivekVaishya You don't need the Holding event for touch screen devices. The RightTapped event just works fine on both touch and mouse-based devices. Your problem is with WebView not raising mouse/touch events at all. – Mehrzad Chehraz Jun 04 '17 at 18:04
  • I tried right tapped event and it works on desktop( that is non-touch) even with webview .But none of the other events such as holding, tapped, manipulation(all of them) are working on mobile. It could be a problem with mobile not recognizing holding event, can it be possible? – killerthawne Jun 05 '17 at 04:29
  • I understood what you meant to say. Do you have an example in javascript to recognize holding event ? Please elaborate it, if possible (as I'm like newbie to js). – killerthawne Jun 05 '17 at 04:39
  • @VivekVaishya [Here](https://stackoverflow.com/questions/4909167/how-to-add-a-custom-right-click-menu-to-a-webpage) you can find an answer for showing context menu in javascript. – Mehrzad Chehraz Jun 05 '17 at 15:02