2013-03-26 337 views
3

我有一个webbrowser,我正在加载一个.html文件。问题是,虽然我已经将ScrollViewer.VerticalScrollBarVisibility设置为“隐藏”,但滚动条仍然可见。隐藏webBrowser滚动条wpf

我也尝试过这种方法,它不工作

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

能否请你提出什么吗?

+0

显然这个解决方案不起作用:http://stackoverflow.com/questions/12930297/disable-wpf-webbrowser-scrollbar。你解决了这个问题吗? – Mikhail 2014-02-06 10:27:06

回答

0

将Microsoft.mshtml添加到您的项目引用。您不需要更改xaml中的任何滚动属性,因为它们不是在使用mshtml时控制WebBrowser的滚动属性。

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

我使用Windows解决了这个问题,在WPF项目形成WebBrowser控件:

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用于在LoadCompleted功能有如下你会做更改网页浏览器的实际文件作为webBrowser1

我们还需要在项目中添加下列程序集的引用的容器: WindowsFormsIntegration程序,System.Windows.Forms的