ChromiumWebBrowser Constructor (HwndSource, String, Size) |
Version 83.4.2
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 posative 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 it's parent control when Loading is complete (
IsLoading is false).
Namespace:
CefSharp.Wpf
Assembly:
CefSharp.Wpf (in CefSharp.Wpf.dll) Version: 83.4.2.0 (83.4.2.0)
Syntaxpublic ChromiumWebBrowser(
HwndSource parentWindowHwndSource,
string initialAddress,
Size size
)
public:
ChromiumWebBrowser(
HwndSource^ parentWindowHwndSource,
String^ initialAddress,
Size size
)
Parameters
- parentWindowHwndSource
- Type: System.Windows.Interop.HwndSource
HwndSource for the Window that will host the browser. - initialAddress
- Type: System.String
address to be loaded when the browser is created. - size
- Type: System.Windows.Size
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