Home > DeveloperSection > Forums > How do I scroll a WPF WebBrowser control to the end?
ezra heywood
ezra heywood

Total Post:145

Posted on    July-19-2013 2:53 AM


 1 Reply(s)
 5242  View(s)
Rate this:
<WebBrowser x:Name="messageBufferWebBrowser"

     controls:WebBrowserUtility.Body="{Binding MessageBuilder}"/>

I'm using this class to enable binding to the Body of the 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))







That's my WebBrowser, I'm binding it to a StringBuilder property on the ViewModel. How can I get the WebBrowser control to scroll to the end?

Vijay Shukla

Total Post:100

Posted on    July-19-2013 6:22 AM

If you cast the WebBrowser's Document property to a mshtml.HTMLDocument, then you can scroll to a specific position in the page (or the bottom by using the largest value possible):

var html = webBrowser.Document as mshtml.HTMLDocument;

html.parentWindow.scroll(0, int.MaxValue);

Note you have to add a reference to Microsoft.mshtml in your project.

Don't want to miss updates? Please click the below button!

Follow MindStick