|
Rank: Advanced Member Groups: Member
Joined: 5/6/2016 Posts: 30
|
Hi! Currently, I'm in a situation, where I have to put a lot of Browsers inside a ScrollViewer. On the left of this ScrollViewer there is an other control, which should be visible despite the scroll offset of the ScrollViewer. The problem is that the WebBrowser is not clipping itself and overlaps the other control. I am aware that the WebView has its own WindowHandle and it only sits on the WPF Window, so I tried to clip it myself, but I stucked because, altough the WebPage itself is clipped it seems that there is a border or something around it, which doesn't get clipped. Quote: [DllImport("GDI32.DLL", EntryPoint = "CreateRectRgn")] private static extern IntPtr CreateRectRgn(Int32 x1, Int32 y1, Int32 x2, Int32 y2);
[DllImport("User32.dll", SetLastError = true)] private static extern Int32 SetWindowRgn(IntPtr hWnd, IntPtr hRgn, Boolean bRedraw);
private void OnScrollChanged(object sender, ScrollChangedEventArgs scrollChangedEventArgs) { var scrollViewer = sender as ScrollViewer; if(scrollViewer == null) return;
System.Windows.Point targetLoc = this.PointToScreen(new System.Windows.Point(0, 0)); Int32 topLeftx = Convert.ToInt32(scrollViewer.HorizontalOffset); Int32 topLeftY = Convert.ToInt32(scrollViewer.VerticalOffset); Int32 bottomRightX = Convert.ToInt32(targetLoc.X + ActualWidth); Int32 bottomRightY = Convert.ToInt32(targetLoc.Y + ActualHeight);
IntPtr hrgn = CreateRectRgn(topLeftx, topLeftY, bottomRightX, bottomRightY); SetWindowRgn(_webView.Handle, hrgn, true); }
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, Can you try to create a test project to demonstrate the problem and send it to us? See here for more details: http://www.essentialobjects.com/forum/test_project.aspxThanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 5/6/2016 Posts: 30
|
Unfortunately, I need to solve this until tomorrow. But the problem is the same as someone mentioned in an other topic here. For the test project tough. If you create put a grid with two coulumns inside a scrollviewer, then put a textblock or anithing in the left column and a WebControl in the right column, then make it big enough so the scrollviewer can scroll, then you can see the problem. It's release time for us, but if I have time, then I put on a test project real fast to you. Thank you in advance!
|
|
Rank: Advanced Member Groups: Member
Joined: 5/6/2016 Posts: 30
|
I've got some time free, so I created and sent a test project for you.
I think the problem is that I clip the WebView's area, I'm using the SetWindowRgn extern function, giving it the WebView's HWnd, thus it will cut the WebView just fine. But there is some kind of other control inside of the WebControl itself that doesn't get clipped. I think it's some kind of WinFormsHost control or something like that. If I could get the HWnd of that thing, then I could fix this.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
We have looked into the test project you sent to us. Indeed there is an internal parent window to WebView.Handle. We will change our code to return the parent window handle instead of the child window handle for WebView.Handle. In the mean time, you can use GetParent API to get the parent window of WebView.Handle, and then clip the parent window instead.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 5/6/2016 Posts: 30
|
Thank you, with the GetParent API it works fine. I could think about that too. Anyway, it would be really good if you could somehow support of adding ScrollViewers which the WebControl listens and clips itself. If anybody is struggling with this problem, then here is a piece of code that works just fine for me: Clip WPF WebControl inside a ScrollViewerThere are parts that shoulb be replaced of course, but it's not that specific to my architecture, so I think its a good start for anyone. It works only with one scrollViewer, so you have to register to the correct ScrollViewer's ScrollChanged event, but I think that with some little work it acn be extended to find all scrollViewer in the Visualtree and calculate the correct Rect from them.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Thank you very much for sharing and your great feedback!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
This is just to let you know that we have posted a new build that changed WebView.Handle to return the root handle instead of the internal browser handle. You can download the new build from our download page.
Thanks!
|
|