Is there a way to render WPF controls on top of the wpf WebBrowser control?

后端 未结 6 879
长情又很酷
长情又很酷 2020-12-16 03:51

I need an embedded WebBrowser control in my application, and am having problems displaying WPF content on top of it. The application will sometimes show popups for editing d

相关标签:
6条回答
  • 2020-12-16 03:58

    Embedded WebBrowsers suck, unfortunately. If you're displaying actual, real, dynamic web content in your WebBrowser, you have to go through the pain of linking another Window to your hosted WebBrowser's window, and handling moving/resizing/et al yourself. I haven't seen another way that works.

    If you're displaying static content (or content from a source that you can control or influence), you might consider displaying, say, RTF docs in a DocumentViewer instead, which doesn't have the icky airspace issues of the WebBrowser control.

    0 讨论(0)
  • 2020-12-16 03:58

    One way you can get around airspace issues is by creating a new frameless window and positioning it on top the webbrowser control. The main problem with this is keeping it positioned properly when the main window get moved/resized/etc.

    0 讨论(0)
  • 2020-12-16 04:01

    The WPF 4.0 Chromium WebBrowser project is an alternative to the built in WebBrowser control that should do what you need.

    0 讨论(0)
  • 2020-12-16 04:07

    The workaround that you could do is by making the height of the web browser control to zero, when some other control comes in front of Web browser control.

    FIX: The standard fix is you can set the height of web browser to zero when you trigger some other control over it depends upon your scenario. Below, there is a sample implementation.

    In MainWindow.Xaml include the events.

    Activated="Window_Activated"
    Deactivated="Window_Deactivated"
    

    In Xaml.cs handle the scenario by setting the height.

    private void Window_Activated(object sender, EventArgs e)
    {
        wb.Height = double.NaN;
    }
    
    private void Window_Deactivated(object sender, EventArgs e)
    {
        wb.Height = 0;
    }
    
    0 讨论(0)
  • 2020-12-16 04:09

    Another methodology that I've had some success with was to play around with clipping regions to essentially cut holes in the ActiveX control that is essentially hosted within these WebBrowser wrapper controls. If I have time I'll write up a demonstration of what I've found and try to include an example but I just wanted to share this in case somebody has more time to look into and can beat me to the punch.

    0 讨论(0)
  • 2020-12-16 04:14

    You could use Adorner's to achieve this. http://msdn.microsoft.com/en-us/library/ms753340.aspx

    0 讨论(0)
提交回复
热议问题