ChromiumWebBrowser Constructor (HwndSource, String, Size) |
Version 104.4.240
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: 104.4.240.0 (104.4.240.0)
Syntax public ChromiumWebBrowser(
HwndSource parentWindowHwndSource,
string initialAddress,
Size size
)
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
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(() =>
{
ParentControl.Child = b;
});
}
}
See Also