Primary WinForms APIs:
AxHostWebBrowserPrimary Avalonia APIs:
NativeControlHostIPlatformHandle)TopLevel integration for host-aware behaviors| WinForms | Avalonia |
|---|---|
embedded ActiveX via AxHost |
NativeControlHost with platform-specific child handle |
| handle-manual positioning | NativeControlHost automatic host/visibility positioning |
built-in WebBrowser control |
custom wrapper around external webview technology |
Avalonia core 11.3.12 does not ship a direct drop-in WebBrowser control equivalent.
Recommended approach:
WinForms C#:
var browser = new WebBrowser { Dock = DockStyle.Fill };
browser.Navigate("https://example.com");
Controls.Add(browser);
Avalonia XAML:
<local:EmbeddedWebHost xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp.Controls"
Width="800"
Height="600" />
using Avalonia.Controls;
using Avalonia.Controls.Platform;
using Avalonia.Platform;
public class EmbeddedNativeHost : NativeControlHost
{
protected override IPlatformHandle CreateNativeControlCore(IPlatformHandle parent)
{
// Replace this with your platform-specific control/webview creation logic.
return base.CreateNativeControlCore(parent);
}
protected override void DestroyNativeControlCore(IPlatformHandle control)
{
// Dispose platform-native resources created in CreateNativeControlCore.
base.DestroyNativeControlCore(control);
}
}
TopLevel and has non-zero bounds.DestroyNativeControlCore.