ChromiumWebBrowser(HwndSource, String, Size) Constructor |
Version 130.1.90
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.WpfAssembly: CefSharp.Wpf (in CefSharp.Wpf.dll) Version: 129.0.110.0 (129.0.110.0)
Syntax public ChromiumWebBrowser(
HwndSource parentWindowHwndSource,
string initialAddress,
Size size
)
public:
ChromiumWebBrowser(
HwndSource^ parentWindowHwndSource,
String^ initialAddress,
Size size
)
Parameters
- parentWindowHwndSource HwndSource
- HwndSource for the Window that will host the browser.
- initialAddress String
- address to be loaded when the browser is created.
- size Size
- size
Example
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