How to scroll the WPF WebBrowser control to the end?

<WebBrowser x:Name="messageBufferWebBrowser" controls:WebBrowserUtility.Body="{Binding MessageBuilder}"/> 

I use this class to enable binding to the body of a WebBrowser control

 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); } } } } 

What is my WebBrowser, I bind it to the StringBuilder property in the ViewModel. How can I make the WebBrowser control scroll to the end?

+4
source share
1 answer

If you pass the WebBrowser Document property to the mshtml.HTMLDocument file, you can go to a specific position on the page (or below, using the highest possible value):

 var html = webBrowser.Document as mshtml.HTMLDocument; html.parentWindow.scroll(0, 10000000); 

Please note that you must add the link to Microsoft.mshtml in your project.

+6
source

All Articles