2

I want to put over WPF WebBrowser some UIElement (opacity = 0) ie and catch all click events via this overplaced UIElement.

Is it possible to do?

This code doesn't work...

<Canvas Name="cnsMain">
  <WebBrowser x:Name="MainBrowser" Visibility="Visible" Panel.ZIndex="0" />
  <Canvas Panel.ZIndex="100" Opacity="0.01"></Canvas>
</Canvas>

Thanks!

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
NoWar
  • 36,338
  • 80
  • 323
  • 498
  • 1
    Seems trivial to try. Did you? –  Feb 09 '12 at 14:57
  • possible duplicate of [How can I put WebBrowser display behind my control?](http://stackoverflow.com/questions/9039593/how-can-i-put-webbrowser-display-behind-my-control) – EricLaw Feb 27 '14 at 13:44

3 Answers3

5

No, you can't do it with the WPF WebBrowser that originally ship with SDK. It always on top of other UIElement.

But I think it is possible with 3rd party control.

For detail take a look in this question I asked before.

Community
  • 1
  • 1
King Chan
  • 4,212
  • 10
  • 46
  • 78
3

No, the WPF Webbrowser is just the standard browser control in a WPF wrapper. It is not native WPF and therefore does not respect the ZOrder of WPF apps.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
GazTheDestroyer
  • 20,722
  • 9
  • 70
  • 103
1

This can be done in .NET 4.5. It requires setting the following properties on your WebBrowser control before it is ever rendered:

IsRedirected = true
CompositionMode = System.Windows.Interop.CompositionMode.Full

This will enable hwnd redirection, allowing the normal top-level hwnd used for rendering to be redirected to a WPF surface that can play nice with other elements in your tree.

EDIT: It would seem this feature was yanked out of .NET 4.5 prior to release. My apologies if I gave anyone false hope. Thanks to @JoeDaley for pointing out my error.

Mike Strobel
  • 25,075
  • 57
  • 69
  • Thank you to share your answer! – NoWar Nov 12 '13 at 18:58
  • 2
    Where are these properties? They don't exist on my .NET 4.5 WebBrowser control, and all I can find searching the net are posts from 2012 about how these properties were removed from .NET 4.5 before its final release. http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2644120-bring-back-the-hwndhost-isredirected-and-compositi – Joe Daley Feb 27 '14 at 02:21
  • @JoeDaley Whoops, it would seem you are correct. Funny that nobody caught that until now. – Mike Strobel Feb 27 '14 at 13:40