Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在UWP中获得WebView上的scrollYOffset?_Webview_Uwp_Scrolltop - Fatal编程技术网

如何在UWP中获得WebView上的scrollYOffset?

如何在UWP中获得WebView上的scrollYOffset?,webview,uwp,scrolltop,Webview,Uwp,Scrolltop,我在VisualStudio上尝试了这段代码。但它变成了: System.Exception:“来自HRESULT:0x80020101的异常” 我如何解决它 string function = @"window.external.notify(document.body.scrollTop)"; await PinView.InvokeScriptAsync("eval", new string[] { function }); System.Exception:“来自HRESULT:0x

我在VisualStudio上尝试了这段代码。但它变成了:

System.Exception:“来自HRESULT:0x80020101的异常”

我如何解决它

string function = @"window.external.notify(document.body.scrollTop)";

await PinView.InvokeScriptAsync("eval", new string[] { function });
System.Exception:“来自HRESULT:0x80020101的异常”

web视图内容中的脚本可以使用window.external.notify和字符串参数将信息发送回应用程序。但是,document.body.scrollTop的类型是number。因此,您应该将参数转换为字符串

string function = @"window.external.notify(document.body.scrollTop.toString())";
await MyWebView.InvokeScriptAsync("eval", new string[] { function});
要接收这些消息,请处理ScriptNotify事件

private void MyWebView_ScriptNotify(object sender, NotifyEventArgs e)
{
    MyText.Text = e.Value.ToString();
}

谢谢我理解。我试过这根绳子。但仍向系统发出警报。异常:“来自HRESULT的异常:0x80020101”。我不知道为什么?字符串函数=@window.external.notifydocument.documentElement.scrollTop.toString;我也错了。非常感谢!我解决了这个问题。在呈现页面之前,运行脚本会出错。完成后脚本运行良好。