Reputation: 219
I have a webbrowser
control and a canvas
in grid
row 0 & 1 receptively.
canvas have large picture and makes a horizontal scroll on grid.
So when i scroll down the webbrowser
is floating on every control, where it should have scrolled within grid
along canvas.
please guide what might be problem.
The code is here:
var wb = new WebBrowser();
wb.NavigateToString(@"<html><head><style> h1{color:red} </style></head><body>
<h-1>HTML code go here</h-1>
<h-1>HTML code go here</h-1>
</body></html>");
wb.Width = 700;
wb.Height = 200;
Grid.SetRow(wb, 0);
T1Grid.Children.Add(wb);
var imagePath = AppDomain.CurrentDomain.BaseDirectory + "images/Jellyfish.jpg";
var mainBitmap = new BitmapImage();
mainBitmap.BeginInit();
mainBitmap.UriSource = new Uri(@"" + imagePath, UriKind.RelativeOrAbsolute);
mainBitmap.EndInit();
_canvas = new Canvas
{
Width = mainBitmap.PixelWidth,
Height = mainBitmap.PixelHeight,
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left
};
var imageBrush = new Image { Source = mainBitmap };
_canvas.Children.Add(imageBrush);
Grid.SetRow(_canvas, 1);
T1Grid.Children.Add(_canvas);
xaml
<TabControl Grid.Row="1">
<TabItem Header="TabItem1">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Grid x:Name="T1Grid" Background="Aqua">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
</Grid>
</ScrollViewer>
</TabItem>
<TabItem Header="TabItem2">
<Grid x:Name="T2Grid" Background="Aqua">
</Grid>
</TabItem>
<TabItem Header="TabItem3">
<Grid x:Name="T3Grid" Background="Aqua">
</Grid>
</TabItem>
</TabControl>
Upvotes: 0
Views: 2650
Reputation: 69959
I had a look at your code and even tried replicating it in XAML, but there really is a problem there. Something is keeping the WebBrowser
control at a certain size and somehow its z-index appears to always be on top.
After looking into it, I found out that it's because of the way it was implemented. From @SvenG's answer to the WPF c# webbrowser scrolls over top menu question here on Stack Overflow:
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.
The linked question also contains links to more information. Also see the links in the Why WPF WebBrowser Control is always on top ? post on the Visual Studio Forum for further information.
Upvotes: 1