简体   繁体   中英

How do I get a WinUI Control's parent Window?

I need to get a reference to the parent Microsoft.UI.Xaml.Window for a Control . Is there a way to do that in Project Reunion 0.5? Window.Current does not work in a desktop app.

On WinUI3 since the window is platform-dependent you access it differently. For Windows Desktop it uses Win32Inerop:

private AppWindow GetAppWindowForCurrentWindow()
        {
            IntPtr hWnd = WindowNative.GetWindowHandle(this);
            WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
            return AppWindow.GetFromWindowId(wndId);
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM