Search code examples
wpfchromium-embeddedcefsharp

CefSharp ChromiumWebBrowser is not displaying the page


I'm trying to programmatically add a ChromiumWebBrowser control to an application I'm developing. These are the steps I'm following:

CefSettings settings = new CefSettings()
{
    PackLoadingDisabled = true,
};

Cef.Initialize(settings);

_webControl = new ChromiumWebBrowser()
{
    Width = this.ElementWidth,
    Height = this.ElementHeight
};

_webControl.Loaded += (sender, e) =>
{
    _webControl.Address = "http://www.google.com";
};

grid.Children.Add(_webControl);

But I can't get it displaying anything. Am I missing something?


Solution

  • The problem was that I was doing

    grid.Children.Add(_webControl);
    

    before

    InitializeComponent();
    

    Swapping the order made the code work.