I am trying to hide the webbrowser scrollbar, but it is still visible.
XAML:
<WebBrowser Name="wb" Width="700" Height="600"
OverridesDefaultStyle="False"
ScrollViewer.CanContentScroll="False"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden" />
Thank you.
Adding scroll="no"
to the html body
tag worked for me while other suggestions here did not.
This works for me:
<WebBrowser LoadCompleted="wb_LoadCompleted"></WebBrowser>
void wb_LoadCompleted(object sender, NavigationEventArgs e)
{
string script = "document.body.style.overflow ='hidden'";
WebBrowser wb = (WebBrowser)sender;
wb.InvokeScript("execScript", new Object[] { script, "JavaScript" });
}
This way you don't need mshtml
Not ideal but it works :
Add Microsoft.mshtml to your project references. Then change your xaml to this :
<WebBrowser Name="wb" Width="700" Height="600"
OverridesDefaultStyle="False"
ScrollViewer.CanContentScroll="False"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
LoadCompleted="wb_LoadCompleted"></WebBrowser>
and in your code behind :
private void wb_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
mshtml.IHTMLDocument2 dom = (mshtml.IHTMLDocument2)wb.Document;
dom.body.style.overflow = "hidden";
}
in your html ....
html{overflow:hidden;}
it should solve it or you can use meta tag to specify Ie render mode
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
Add Microsoft.mshtml to your project references. You dont 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 do the following:
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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With