Chromiumwebbrowser-如何将高度设置为HTML Doc Height
我的应用程序中有一个托管的Chromiumwebbrowser。 用户可以在html页面之间导航(带有bing tor地址)。
我需要XAML滚动器(不是CSS),所以我有一个ScrollViewer,并且在Chromium浏览器内部。
每次地址更改时,铬高度都需要完整的HTML DOC高度,才能正确滚动。
我尝试将其设置为类似的答案,以在此Q中回答: cefsharp Chromiumwebbrowser to Page Content to Page
Content它只会增长 - 如果第一页为600,而下一页是200-第二次返回600次。
XAML:
<ScrollViewer x:Name="scroller" >
<wpf:ChromiumWebBrowser x:Name="chrome"
Address="{Binding CurrentUrl}" />
</ScrollViewer>
C#:
chrome.LoadingStateChanged += async (s, e) =>
{
if (!e.IsLoading) // browser.CanExecuteJavascriptInMainFrame == TRUE !
{
JavascriptResponse response =
await chrome.EvaluateScriptAsync(
// GET HEIGHT OF CONTENT
$"(function() " +
"{ var _docHeight = " +
" document.documentElement.scrollHeight; " +
" " +
" return _docHeight; " +
"} " +
")();");
int docHeight = (int)response.Result;
chrome.Dispatcher.Invoke(() => { chrome.Height = docHeight; });
}
};
I have a chromiumWebBrowser hosted in my application.
user can navigate between html pages (with binging to address).
I need xaml scroller (not css), so I have a scrollViewer and inside the Chromium browser.
Every time the Address changes, chromium height needs to be full html doc height, to get the scrolling right.
I have tried setting it similar to answer in this Q:
cefSharp ChromiumWebBrowser size to page content
which works well first time, but when navigating, it only grows - if first page is 600, and next is 200 - it returns 600 second time too.
XAML:
<ScrollViewer x:Name="scroller" >
<wpf:ChromiumWebBrowser x:Name="chrome"
Address="{Binding CurrentUrl}" />
</ScrollViewer>
C#:
chrome.LoadingStateChanged += async (s, e) =>
{
if (!e.IsLoading) // browser.CanExecuteJavascriptInMainFrame == TRUE !
{
JavascriptResponse response =
await chrome.EvaluateScriptAsync(
// GET HEIGHT OF CONTENT
quot;(function() " +
"{ var _docHeight = " +
" document.documentElement.scrollHeight; " +
" " +
" return _docHeight; " +
"} " +
")();");
int docHeight = (int)response.Result;
chrome.Dispatcher.Invoke(() => { chrome.Height = docHeight; });
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论