[英]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
.我需要为
Control
获取对父Microsoft.UI.Xaml.Window
的引用。 Is there a way to do that in Project Reunion 0.5? Project Reunion 0.5 中有没有办法做到这一点?
Window.Current
does not work in a desktop app. Window.Current
在桌面应用程序中不起作用。
On WinUI3 since the window is platform-dependent you access it differently.在 WinUI3 上,因为 window 依赖于平台,因此您可以以不同的方式访问它。 For Windows Desktop it uses Win32Inerop:
对于 Windows 桌面,它使用 Win32Inerop:
private AppWindow GetAppWindowForCurrentWindow()
{
IntPtr hWnd = WindowNative.GetWindowHandle(this);
WindowId wndId = Win32Interop.GetWindowIdFromWindow(hWnd);
return AppWindow.GetFromWindowId(wndId);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.