我有一个带有菜单和滚动查看器的网格.在滚动查看器中,我有一个带有另一个网格和 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.
现在,当我使窗口小于浏览器内容的内容并在滚动查看器中向下滚动时,问题就出现了.一切都有一个边距,所以它保持在顶部菜单的下方,但是 webbrowser 元素没有,因此覆盖了菜单.有没有办法解决这个问题?我想不通 :s Margins &填充不起作用.我希望它周围的网格元素或其他东西可以解决问题,但没有任何效果.
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 代码,但请记住它非常庞大,所以这是极短的版本:(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 控件,并且在技术上呈现在 WPF 内容之上.此外,它在尺寸计算方面存在一些严重问题.
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 上找到了一个很好的总结,其中指出了一些替代方案:
Found a great summary here on SO which points to some alternatives:
WPF WebBrowser (3.5 SP1) 总是在最前面 - 在 WPF 中显示 HTML 的其他建议
这篇关于WPF c# webbrowser 在顶部菜单上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!