Third party libraries
Avalonia XPF implements WPF's API surface, however a variety of third party libraries also depend on various win32 APIs which are obviously not available cross-platform.
To deal with this problem, Avalonia XPF implements a win32 API emulation layer that allows 3rd party libraries to work on non-windows platforms. This emulation layer needs to be enabled explictly in your XPF application.
This feature must be enabled before any assembly attempts to call a win32 API, so the constructor of your App
class or Program.Main
is a good place to enable it.
To enable win32 API emulation application-wide you can add the following call:
AvaloniaUI.Xpf.WinApiShim.WinApiShimSetup.AutoEnable();
You can exclude libraries that are known to provide non-windows platform support like this:
AvaloniaUI.Xpf.WinApiShim.WinApiShimSetup.
.AutoEnable(asm =>
{
var name = asm.GetName().Name.ToLowerInvariant();
if (name is "sqlite" or "jint" or "esprima" or "magick.net" or "magick.net.core")
return true;
return false;
});
Alternatively the layer can be enabled on per-library basis:
AvaloniaUI.Xpf.WinApiShim.WinApiShimSetup
.AddLibrary(typeof(Type.In.Third.Party.Library).Assembly);
Compatibility Database
We maintain a comprehensive compatibility database for third-party controls. This database provides up-to-date status information for controls from major vendors.
If you find that a control marked as Fix In Progress
or Untested
is mission-critical for your application, please contact our support team. We're committed to working with you to ensure compatibility.
Compatibility Notes
- Pure WPF Controls: Third-party controls that are implemented purely in WPF typically work without any issues, even if not listed in our compatibility database.
- Unlisted Vendors: The absence of a control vendor from our database doesn't indicate incompatibility. We encourage you to test any controls you need.
- Known Challenges: Issues most commonly arise with controls that utilize GDI or WinForms components.
WinAPI Shim APIs
Below is an overview of the Windows API (WinAPI) shims available in Avalonia XPF. These shims allow for native Windows functionality while maintaining cross-platform compatibility. Some APIs may not be fully implemented.
Window Management
Window Creation and Manipulation
// Window Creation
IntPtr CreateWindowEx(uint dwExStyle, void* lpClassName, void* lpWindowName, uint dwStyle,
int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu,
IntPtr hInstance, IntPtr lpParam);
IntPtr CreateWindowExW(uint dwExStyle, void* lpClassName, void* lpWindowName, uint dwStyle,
int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu,
IntPtr hInstance, IntPtr lpParam);
short RegisterClass(void* wc);
short RegisterClassExW(WNDCLASSEX* lpwcx);
// Window State and Properties
int GetWindowPlacement(IntPtr hWnd, IntPtr lpwndpl);
int GetWindowRect(IntPtr hWnd, RECT* lpRect);
int GetClientRect(IntPtr hWnd, RECT* lpRect);
int IsWindowEnabled(IntPtr hWnd);
int IsWindowVisible(IntPtr hWnd);
int IsWindow(IntPtr hWnd);
int GetWindowInfo(IntPtr hwnd, WINDOWINFO* pwi);
// Window Position and Layout
IntPtr BeginDeferWindowPos(int nNumWindows);
int EndDeferWindowPos(IntPtr hWinPosInfo);
int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
uint AdjustWindowRectEx(RECT* lpRect, uint dwStyle, uint bMenu, uint dwExStyle);
// Window Properties
int GetWindowLong(IntPtr hWnd, int nIndex);
int SetWindowLong(IntPtr hWnd, int nIndex, int newVal);
IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
IntPtr GetWindowLongPtrW(IntPtr hWnd, int nIndex);
IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr newVal);
// Window Hierarchy and Relations
IntPtr GetActiveWindow();
IntPtr GetTopWindow(IntPtr hWnd);
IntPtr GetWindow(IntPtr hWnd, uint uCmd);
IntPtr GetDesktopWindow();
IntPtr WindowFromPoint(long p);
IntPtr FindWindow(void* lpClassName, void* lpWindowName);
int EnumChildWindows(IntPtr window, IntPtr callback, IntPtr lParam);
// Window Display and Region
int SetWindowDisplayAffinity(IntPtr hWnd, int* dwAffinity);
int SetWindowRgn(IntPtr hWnd, IntPtr hRgn, int bRedraw);
int RedrawWindow(IntPtr hWnd, RECT* lprcUpdate, IntPtr hrgnUpdate, uint flags);
int InvalidateRect(IntPtr hWnd, RECT* lpRect, int bErase);
// System Menu
IntPtr GetSystemMenu(IntPtr hWnd, int bRevert);
Focus and Input Management
IntPtr GetFocus();
IntPtr GetCapture();
int ReleaseCapture();
int SetForegroundWindow(IntPtr hWnd);
short GetKeyState(int vKey);
int GetMessagePos();
int GetMessageTime();
int GetCursorPos(POINT* lpPoint);
Graphics and Device Context
Device Context Management
IntPtr GetDC(IntPtr hWnd);
IntPtr CreateCompatibleDC(IntPtr hdc);
int DeleteDC(IntPtr hdc);
int GetDeviceCaps(IntPtr hdc, int nIndex);
int ReleaseDC(IntPtr hWnd, IntPtr hDC);
Region and Drawing Objects
IntPtr CreateRectRgn(int x1, int y1, int x2, int y2);
IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int cx, int cy);
IntPtr CreateRectRgnIndirect(RECT* lprc);
int DeleteObject(IntPtr obj);
IntPtr GetStockObject(int i);
Coordinate System and Mapping
int GetMapMode(IntPtr hdc);
int SetMapMode(IntPtr hdc, int fnMapMode);
int SetWindowExtEx(IntPtr hdc, int x, int y, SIZE* lpsz);
int SetViewportExtEx(IntPtr hdc, int x, int y, SIZE* lpsz);
int OffsetRect(IntPtr lprc, int x, int y);