3

I have a webbrowser and I am loading a .html file. The problem is that although I have already set the ScrollViewer.VerticalScrollBarVisibility to"Hidden", the scrollbar is still visible.

I have also tried this approach and it is not working

<WebBrowser x:Name="personalizedWebBrowser" HorizontalAlignment="Left"  VerticalAlignment="Top" 
                ScrollViewer.CanContentScroll="False"
                ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
                ScrollViewer.VerticalScrollBarVisibility="Hidden"
                LoadCompleted="wb_LoadCompleted"/>


private void wb_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
     mshtml.IHTMLDocument2 dom = (mshtml.IHTMLDocument2)personalizedWebBrowser.Document;
     dom.body.style.overflow = "hidden";
}

Could you please suggest anything else?

J. Steen
  • 15,470
  • 15
  • 56
  • 63
AlexandruMN
  • 63
  • 2
  • 8
  • Apparently this solution does not work: http://stackoverflow.com/questions/12930297/disable-wpf-webbrowser-scrollbar. Have you solved this problem? – Mikhail Poda Feb 06 '14 at 10:27

3 Answers3

2

I solved this problem by using windows forms WebBrowser control in wpf project:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        string curDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\help";

        System.Windows.Forms.Integration.WindowsFormsHost host =
            new System.Windows.Forms.Integration.WindowsFormsHost();
        System.Windows.Forms.WebBrowser webBrowser1 = new System.Windows.Forms.WebBrowser();
        host.Child = webBrowser1;

        webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;

        string sFileName = "file:///{0}/index.html";

        webBrowser1.Url = new Uri(String.Format(sFileName, curDir));
        webBrowser1.ScrollBarsEnabled = false;
        this.grid1.Children.Add(host);
    }

    private void webBrowser1_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
    {
        System.Windows.Forms.WebBrowser webBrowser1 = sender as System.Windows.Forms.WebBrowser;
        if(webBrowser1==null)return;
        webBrowser1.Document.Body.Style = "overflow:hidden";
    }

grid1 is used as a container for webBrowser1

We also need to add in the project the following assembly references: WindowsFormsIntegration, System.Windows.Forms

0

Add Microsoft.mshtml to your project references. You don't need to change any of the scroll properties in xaml as they are not the one controlling the WebBrowser when mshtml is used. In the LoadCompleted function there you will make changes to the actual document of the webbrowser as follows:

private void webBrowserChat_LoadCompleted(object sender, NavigationEventArgs e)
{
    mshtml.IHTMLDocument2 documentText = (IHTMLDocument2)webBrowserChat.Document; 
    //this will access the document properties 
    documentText.body.parentElement.style.overflow = "hidden"; 
   // This will hide the scrollbar (Set to "auto" if you want to see when it passes the surfacelimit)
}
Devdude
  • 99
  • 7
0

For vb.net using VS2019, modifying DevDude's solution as follows has worked:

Private Sub webObjectLoaded(ByVal sender as WebBrowser, Byval as NavigationEventArgs)
  Dim dom as MSHTML.IHTMLDocument2 = sender.Document
  dom.body.style.overflow = "hidden"
End Sub

I had multiple browser displayed in a stack panel, so that calling code looked something like this:

Dim wb = New WebBrowser()
wb.NavigateToString(txt)
AddHandler wb.LoadCompleted, AddressOf webObjectLoaded

I added a reference to "Microsoft HTML Object Library" from COM which seems to show as Interop.MSHTML in the list of references.