简体   繁体   English

在Webview(UWP)中启用触摸事件

[英]Enable touch events in a webview (UWP)

I need to enable touch events in a webview in an UWP-app (Universal Windows Platform). 我需要在UWP-app(通用Windows平台)中的webview中启用触摸事件。

It is possible to set this flag in the local installed edge browser: Type "about:flags" in the edge browser and move to "Touch events". 可以在本地安装的边缘浏览器中设置此标志:在边缘浏览器中键入“about:flags”并移至“触摸事件”。 Default it is set to "Always off". 默认设置为“始终关闭”。

Can i set this flag programmatically in a webview instance in my UWP-app? 我可以在我的UWP-app中的webview实例中以编程方式设置此标志吗?

Background: I need all touch events in a website to pan a digital map. 背景:我需要网站中的所有触摸事件来平移数字地图。

Let me know if you need more information. 如果您需要更多信息,请与我们联系。

Webview: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.webview Webview: https//docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.webview

Unfortunately, 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 . 不幸的是,如事件表中所示, WebView不支持从UIElement继承的大多数用户输入事件,例如KeyDownKeyUpPointerPressed Details please reference the remarks of the WebView class. 详细信息请参考WebView类的备注 And the relative team is working on enable Manipulation Events for WebView that you may vote that. 相关团队正致力于为WebView启用Manipulation Events ,您可以对其进行投票。

As the remarks mentioned, 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 . 如上所述,常见的解决方法是使用InvokeScriptAsync和JavaScript eval函数来使用HTML事件处理程序,并使用HTML事件处理程序中的window.external.notify来使用WebView.ScriptNotify通知应用程序。 In another words, you may try to capture the touch events inside the website by JavaScript and notify the WebView . 换句话说,您可以尝试通过JavaScript捕获网站内的触摸事件并通知WebView For details about how do to please reference the WebView official sample . 有关如何参考WebView官方示例的详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM