問題描述
我有一個(gè)帶有菜單和滾動(dòng)查看器的網(wǎng)格.在滾動(dòng)查看器中,我有一個(gè)帶有另一個(gè)網(wǎng)格和 webbrowser 元素的 groupbox.
I have a grid with a menu and a scrollviewer inside. In the scrollviewer i have a groupbox with another grid and inside a webbrowser element.
現(xiàn)在,當(dāng)我使窗口小于瀏覽器內(nèi)容的內(nèi)容并在滾動(dòng)查看器中向下滾動(dòng)時(shí),問題就出現(xiàn)了.一切都有一個(gè)邊距,所以它保持在頂部菜單的下方,但是 webbrowser 元素沒有,因此覆蓋了菜單.有沒有辦法解決這個(gè)問題?我想不通 :s Margins &填充不起作用.我希望它周圍的網(wǎng)格元素或其他東西可以解決問題,但沒有任何效果.
Now the problem arises when i make my window smaller than the content of my webbrowser content, and scroll down in the scrollviewer. Everything has a margin so it stays below the top menu, however the webbrowser element does not, hence covering the menu. Is there a way to solve this? I can't figure it out :s Margins & Paddings don't work. I was hoping the grid element around it or something would do the trick, but nothing works.
好的,我嘗試添加 xaml 代碼,但請(qǐng)記住它非常龐大,所以這是極短的版本:(webbrowser 元素位于代碼的底部)
Ok I tried to add the xaml code but bear in mind it was insanely huge, so this is the extreme short version: (webbrowser element is at the bottom of the code)
<Window x:Class="Cleaning_Masters_Official.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Cleaning Masters Offerte Packet - nieuw.off" Name="Main" Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}"
Icon="binDebugImagesMain.ico"
Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}" Closing="Main_Closing"
WindowStartupLocation="CenterScreen" WindowStyle="SingleBorderWindow" WindowState="Maximized">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="22" />
<RowDefinition Height="*" />
<RowDefinition Name="rowbar" Height="0" />
</Grid.RowDefinitions>
<ScrollViewer Margin="10" Grid.Row="1">
<TabControl Name="tabChapters">
<TabItem Header="Algemeen" Name="tabGeneral">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GroupBox Header="Configureer hoofdstukken:" Margin="10" Padding="10">
<Grid>
...
</Grid>
</GroupBox>
<GroupBox Header="Voorpagina Afbeeldingen:" Margin="10,0,10,10" Padding="10" Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2">
<Grid VerticalAlignment="Top">
...
</Grid>
</GroupBox>
<GroupBox Header="Offerte Info:" Margin="10,10,10,10" Padding="10" Grid.Column="1" Grid.Row="0">
<Grid>
...
</Grid>
</GroupBox>
<GroupBox Margin="0,10,10,10" Header="Inhoudstafel:" Grid.Column="2" Grid.RowSpan="2">
<Grid>
<WebBrowser Margin="10" Name="wbInhoudstafel"/>
</Grid>
</GroupBox>
</Grid>
</TabItem>
<TabItem Header="1. Voorwoord" Name="tabVoorwoord">
</TabItem>
...
</TabItem>
</TabControl>
</ScrollViewer>
<Menu DockPanel.Dock="Top" Name="TopMenu">
...
</Menu>
<StatusBar Name="sbar" Grid.Row="2"
...
</StatusBar>
</Grid>
</Window>
推薦答案
WPF WebBrowser 控件基本上是舊的 Win32 Webbrowser 控件,并且在技術(shù)上呈現(xiàn)在 WPF 內(nèi)容之上.此外,它在尺寸計(jì)算方面存在一些嚴(yán)重問題.
The WPF WebBrowser control is basically the old Win32 Webbrowser control and is technically rendered above the WPF content. Additionally it has some serious issues with size calculations.
見http://msdn.microsoft.com/en-us/library/aa970688(v=vs.85).aspx
恐怕沒有辦法告訴 WebBrowser 控件更改該行為.
I'm afraid there's no way to tell the WebBrowser Control to change that behavior.
但是還有其他控件可供選擇:
But there are alternative controls out there:
http://wpfchromium.codeplex.com/
http://awesomium.com/
在 SO 上找到了一個(gè)很好的總結(jié),其中指出了一些替代方案:
Found a great summary here on SO which points to some alternatives:
WPF WebBrowser (3.5 SP1) 總是在最前面 - 在 WPF 中顯示 HTML 的其他建議
這篇關(guān)于WPF c# webbrowser 在頂部菜單上滾動(dòng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!