Click or drag to resize

ChromiumWebBrowser Constructor (HwndSource, String, Size)

Version 118.6.80
Initializes a new instance of the ChromiumWebBrowser class. Use this constructor to load the browser before it's attached to the Visual Tree. The underlying CefBrowser will be created with the specified size. CEF requires positive values for Width and Height, if values less than 1 are specified then the default value of 1 will be used instead. You can subscribe to the LoadingStateChanged event and attach the browser to its parent control when Loading is complete (IsLoading is false).

Namespace:  CefSharp.Wpf
Assembly:  CefSharp.Wpf (in CefSharp.Wpf.dll) Version: 118.6.80.0 (118.6.80.0)
Syntax
public ChromiumWebBrowser(
	HwndSource parentWindowHwndSource,
	string initialAddress,
	Size size
)

Parameters

parentWindowHwndSource
Type: System.Windows.InteropHwndSource
HwndSource for the Window that will host the browser.
initialAddress
Type: SystemString
address to be loaded when the browser is created.
size
Type: System.WindowsSize
size
Examples
//Obtain Hwnd from parent window
var hwndSource = (HwndSource)PresentationSource.FromVisual(this);
var browser = new ChromiumWebBrowser(hwndSource, "github.com", 1024, 768);
browser.LoadingStateChanged += OnBrowserLoadingStateChanged;

private void OnBrowserLoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
{
  if (e.IsLoading == false)
  {
    var b = (ChromiumWebBrowser)sender;
    b.LoadingStateChanged -= OnBrowserLoadingStateChanged;
    Dispatcher.InvokeAsync(() =>
    {
      //Attach to visual tree
      ParentControl.Child = b;
    });
  }
}
See Also