<WebBrowser x:Name="messageBufferWebBrowser"
controls:WebBrowserUtility.Body="{Binding MessageBuilder}"/>
我正在使用这个类来启用绑定(bind)到 WebBrowser 控件的正文
public static class WebBrowserUtility
{
public static readonly DependencyProperty BodyProperty =
DependencyProperty.RegisterAttached("Body", typeof(string), typeof(WebBrowserUtility), new PropertyMetadata(OnBodyChanged));
public static string GetBody(DependencyObject dependencyObject)
{
return (string)dependencyObject.GetValue(BodyProperty);
}
public static void SetBody(DependencyObject dependencyObject, string body)
{
dependencyObject.SetValue(BodyProperty, body);
}
private static void OnBodyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var webBrowser = d as WebBrowser;
if (!string.IsNullOrWhiteSpace(e.NewValue as string) && webBrowser != null)
{
if (Application.Current.MainWindow != null && !DesignerProperties.GetIsInDesignMode(Application.Current.MainWindow))
{
webBrowser.NavigateToString((string)e.NewValue);
}
}
}
}
那是我的 WebBrowser,我将它绑定(bind)到 ViewModel 上的 StringBuilder 属性。如何让 WebBrowser 控件滚动到末尾?
最佳答案
如果将 WebBrowser 的 Document 属性转换为 mshtml.HTMLDocument,则可以滚动到页面中的特定位置(或使用可能的最大值滚动到底部):
var html = webBrowser.Document as mshtml.HTMLDocument;
html.parentWindow.scroll(0, 10000000);
请注意,您必须添加对
Microsoft.mshtml
的引用在你的项目中。
关于wpf - 如何将 WPF WebBrowser 控件滚动到最后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4350277/