Embed Firefox/Gecko in WPF/C#

前端 未结 5 1702
野的像风
野的像风 2021-02-03 12:30

I want to embed the current Gecko in my WPF-Project. I know there is the possibility with the Winforms-Host and the Skybound-Gecko-Library.

But I do not use the standard

5条回答
  •  情话喂你
    2021-02-03 13:00

    This is an old question, but I came up with a pseudo-solution to add GeckoFX as a XAML tag such as:

    
    

    This can be accomplished by simply wrapping the whole thing in a UserControl such as:

    XAML:

    
          
    
    

    C#:

    public partial class Browser : UserControl
    {
        WindowsFormsHost host = new WindowsFormsHost();
        GeckoWebBrowser browser = new GeckoWebBrowser();
    
        public Browser()
        {
            InitializeComponent();
            Xpcom.Initialize("Firefox");
            browser.Navigate("http://www.google.com");
            host.Child = browser;
            border.Child = host;
        }
    }
    

    Now, you can use the tag in WPF, in the same project where the UserControl exists.

    I have been trying to get this to work as a Control in a library, so I can easily port it to any other project/solution, but it keeps giving me an error about mozglue.dll missing. I suspect this is due to the Xpcom.Initialize("Firefox") but I need to investigate further.

提交回复
热议问题