Search code examples
c#windowsavaloniauiavalonia

How to get windows's handle in windows Avalonia UI?


I want get the handle of window that created by Avalonia UI on Windows platform.

In WPF,it coded with: new WindowInteropHelper(MainWindow.instance).Handle

But I did't get any interface that allows me get the handle of window directly.

I tried this but the complier told me that member donsn't exists.

I've using lasted version of Avalonia UI.

But that Avalonia.Win32.WindowImpl has some protection level so i can't convert the MainWindow.PlatformImpl to Avalonia.Win32.WindowImpl.

Is there any way to get handle of window by original Avalonia UI?


Solution

  • Use the TryGetPlatformHandle method of the TopLevel class, a base class of Window:

    IntPtr? handle = window.TryGetPlatformHandle()?.Handle;