简体   繁体   English

如何获得 WinUI 控件的父级 Window?

[英]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.

相关问题 在尝试获取 window 处理程序时,如何在 WinUI3 中解决此 System.InvalidCastException? - How do I solve this System.InvalidCastException in WinUI3 while trying to get the window handler? 如何从用户控制窗口访问父窗口的控件 - How to Access Parent Window's Control from user control window C# WinUI3 桌面:如何引用或控制 ListView 的所选项目 DataTemplate 中的按钮? - C# WinUI3 Desktop: How can I reference or control a button in a ListView's selected item DataTemplate? 如何获得控件的网格父级? - How do I get the grid parent of my control? 如何在用户控件的页面加载中读取独立于页面的父控件的ID? - How do I read parent control's id in user control's page load, independent of pages? 如何获取“图表系列”的“父母的父母”父母的详细信息? - How do I get the Chart Series' Parent's Parent's Parent's detail? 如何制作一个可以在 WinUI3 中禁用的 TextBlock 控件? - How do a make a TextBlock control that can be disabled in WinUI3? 如何绑定到用户控件的父窗口IsActive属性 - How to bind to user control's parent window IsActive property 如何获取发送路由事件的控件的父控件的列索引? - How do I get the column index of parent control of control that sent the routed event? WinUI3中如何关闭Window? - How to close Window in WinUI3?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM