C# 关闭用户与UWP表单中的WebView的交互

C# 关闭用户与UWP表单中的WebView的交互,c#,windows,xaml,uwp,C#,Windows,Xaml,Uwp,我正在使用Windows.UI.Xaml.Controls.WebView查看某些web内容。我想关闭与组件的所有用户交互。没有键盘事件,没有鼠标事件。我怎样才能做到这一点 我尝试过取消GettingFocus事件,但是在webview中运行的测试javascript仍然会收到鼠标点击 下面是我测试过的代码的一个稍加修改的版本。daWebView是一个WebView组件 public sealed partial class MainPage : Page { public Ma

我正在使用Windows.UI.Xaml.Controls.WebView查看某些web内容。我想关闭与组件的所有用户交互。没有键盘事件,没有鼠标事件。我怎样才能做到这一点

我尝试过取消GettingFocus事件,但是在webview中运行的测试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内容。您可以使用方法注入js方法来禁用交互。有关更多信息,请参阅此。

您能分享您迄今为止的尝试吗?这是否回答了您的问题?尼科,谢谢你的链接。遗憾的是,我需要告诉组件不要监听事件。至少我需要能够拦截并控制它们。WebView组件在我看来太像一个剪切粘贴的浏览器框架了。。我正在尝试替换cefsharp,这是一个很好的软件,只是它在uwp中工作不好。Pavel,请查看我的更新问题。@Snorvarg,没有这样的api可以直接禁用与WebView的交互,更好的方法是使用js injectio禁用
WebView
内容。是的,这也是我发现的。微软没有正确地公开webview的内部工作,这有点懒惰。。