[英]Turn off user interaction with a WebView in a UWP form
我正在使用 Windows.UI.Xaml.Controls.WebView 查看一些 Web 内容。 我想关闭与组件的所有用户交互。 没有键盘事件,没有鼠标事件。 我怎样才能做到这一点?
我已经尝试取消 GettingFocus 事件,但是我在 webview 中运行的 test-javascript 仍然收到鼠标点击。
这是我测试过的代码的稍微修改版本。 daWebView 是一个 WebView 组件。
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
this.RequiresPointer = RequiresPointer.Never;
Application.Current.RequiresPointerMode = ApplicationRequiresPointerMode.WhenRequested;
bool res = daWebView.Focus(FocusState.Unfocused);
daWebView.GettingFocus += DaWebView_GettingFocus;
daWebView.PointerMoved += DaWebView_PointerMoved;
Uri uri = new Uri("ms-appx-web:///index.html");
daWebView.Source = uri;
}
private void DaWebView_PointerMoved(object sender, PointerRoutedEventArgs e)
{
// never happens.
Debug.WriteLine("pointer moved");
}
private void DaWebView_GettingFocus(UIElement sender, GettingFocusEventArgs args)
{
// not working, it still gets focus and receive mouse movement.
args.Cancel = true;
}
}
在 UWP 表单中关闭用户与 WebView 的交互
没有这样的 api 可以直接禁用与 WebView 的交互,更好的方法是通过 js 注入禁用 WebView 内容。 您可以使用InvokeScriptAsync
方法注入 js 方法来禁用交互。 有关更多信息,请参阅此文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.