WPF c# webbrowser scrolls over top menu

2019-02-17 14:27发布

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.

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.

EDIT:

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="bin\Debug\Images\Main.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>

1条回答
我想做一个坏孩纸
2楼-- · 2019-02-17 14:59

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.

See http://msdn.microsoft.com/en-us/library/aa970688(v=vs.85).aspx

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/

Edit:

Found a great summary here on SO which points to some alternatives:

WPF WebBrowser (3.5 SP1) Always on top - other suggestion to display HTML in WPF

查看更多
登录 后发表回答