Welcome Guest Search | Active Topics | Sign In | Register

WebControl overflows its parent container Options
Jack
Posted: Thursday, June 12, 2014 4:18:32 PM
Rank: Newbie
Groups: Member

Joined: 6/12/2014
Posts: 2
Hello,
We are having a problem getting the WebControl to clip to it's parent container. I created a test app to see how it worked outside of our application and found the same behavior. Here is the xaml.

<Window x:Class="TestEO.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:eo="http://schemas.essentialobjects.com/wpf/"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<ScrollViewer>
<eo:WebControl ClipToBounds="True" Height="800" >
<eo:WebControl.WebView>
<eo:WebView Url="www.google.com">
</eo:WebView>
</eo:WebControl.WebView>
</eo:WebControl>
</ScrollViewer>
<Label Grid.Row="1">Jack</Label>
</Grid>
</Window>

If you replace the WebControl with a Canvas of the same height you will see what I would expect, the canvas is constrained to the first row of the grid. If you don't set a height on the webcontrol and remove the scrollviewer it will have the desired behavior for this example but we really need to be able to control scrolling at the parent container level.

Thanks,
Jack
eo_support
Posted: Friday, June 13, 2014 11:33:03 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

There is no simple straight forward way to make the WebControl to honor clip region because the WebControl has its own window and the WPF clipping only occurs inside the parent WPF window. As a workaround, you can handle the ScrollViewer's ScrollChanged event to update the WebControl's position, size and scroll offset so that it would appear that the WebView is scrolling along with your ScrollViewer. The following code demonstrates this concept:

Code: C#
//Hook up the ScrollViewer's ScrollChanged event
scrollViewer1.ScrollChanged += new ScrollChangedEventHandler(scrollViewer1_ScrollChanged);

//The ScrollChanged event handler
void scrollViewer1_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
    //Here it simply syncs the WebControl to the ViewPort. You
    //may need to adapt it to fit your own scenario. For example,
    //you may need to hide a portion of or even the whole 
    //WebControl if it scrolls out of view
    WebControl1.SetValue(Canvas.TopProperty, scrollViewer1.VerticalOffset);
    WebControl1.SetValue(FrameworkElement.HeightProperty, scrollViewer1.ViewportHeight);
    WebControl1.SetValue(FrameworkElement.WidthProperty, scrollViewer1.ViewportWidth);

    //Here it syncs the WebControl's scroll position to the
    //ScrollViewer's scroll position. Again most likely you
    //will need to adapt it to fit your own scenario. For example,
    //you may need to add/substract certain offset to the
    //ScrollViewer's scroll offset. Note that the ScrollViewer's
    //offset is in WPF logical unit, but the WebView uses
    //device unit (pixel), so here we have to convert it
    PresentationSource source = PresentationSource.FromVisual(scrollViewer1);
    Matrix matrix = source.CompositionTarget.TransformToDevice;
    Point p = matrix.Transform(new Point(0, scrollViewer1.VerticalOffset));
    WebControl1.WebView.SetScrollOffset(0, (int)Math.Round(p.Y));
}


Hope this helps. Please feel free to let us know if you have any more question.

Thanks!
Jack
Posted: Wednesday, June 18, 2014 6:54:38 PM
Rank: Newbie
Groups: Member

Joined: 6/12/2014
Posts: 2
Thanks for the reply, we've decided to not try to use the control this way. Thought about implementing our own WindowsFormHost but ultimately for us its not worth it.

Did find a couple of good articles that you guys might be interested in.

http://blogs.msdn.com/b/ryanvog/archive/2009/01/20/clipping-legacy-content-hosted-inside-a-wpf-scrolling-region.aspx
http://www.mycsharp.de/wbb2/thread.php?threadid=76625
eo_support
Posted: Wednesday, June 18, 2014 7:10:09 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Excellent. Thank you very much for sharing the information with us! WPF brings a lot of great features but also introduced a lot of problems. Since EO.WebBrowser works with window handle, it actually works somewhat better in Windows Forms application. I believe the clipping problem is one problem that exists for almost all window based WPF controls --- including MS's own WebBrowser control. So it's a headache for everyone.
Seges Innovation P/S
Posted: Tuesday, April 28, 2020 5:43:30 AM
Rank: Newbie
Groups: Member

Joined: 3/7/2018
Posts: 4
Hi.
This is for anyone else having problem with this.
The solution is to use a WindowsFormsHost (altered) then embed a ElementHost and then adding the WebControl.
So going WPF->Forms->WPF->Forms (WebControl) should do the trick.

I Used the code from this post:
https://stackoverflow.com/questions/14080580/scrollviewer-is-not-working-in-wpf-windowsformhost

combining it with this xaml:
<Grid>
<Border BorderBrush="Black" BorderThickness="2">
<ScrollViewer Background="Aquamarine" >
<local:ScrollViewerWindowsFormsHost >
<ElementHost>
<eo:WebControl x:Name="browser" MinHeight="100"></eo:WebControl>
</ElementHost>
</local:ScrollViewerWindowsFormsHost>
</ScrollViewer>
</Border>
</Grid>

If MinHeight is removed the area will be black.

Best regards
Martin

eo_support
Posted: Tuesday, April 28, 2020 12:45:37 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Thanks for sharing!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.