1

I am working on a C++ WinUI3 project and got this problem. How do I obtain the handle of a XAML grid?

Something like this in QT can achieve it:

HWND m_hWnd;

m_hWnd = (HWND)(ui.label->winId());

But I couldn't find the similar thing in WinUI3. I look up on the Internet, but only find this solution which is in C#:

Get-a-controls-handle-in-XAML

And the Microsoft provide this, but it is only working for window handle, not XAML controls.

Retrieve a window handle (HWND)

Could anyone help me with it? Any suggestions will be great!

2
  • 1
    XAML is a windowless framework. Controls don't have windows. Commented May 10, 2022 at 3:56
  • Thanks. Do you have any idea how to get controls / elements handle?
    – Clara2022
    Commented May 10, 2022 at 5:24

1 Answer 1

4

How do I obtain the handle of a XAML grid?

You can't because there is none.

All XAML controls on the screen are ultimately backed by a single HWND that belongs to the parent window, i.e. an individual control doesn't have its own handle in Win UI.

There is only a single top-level handle and the controls are rendered as content inside this HWND.

1
  • Thank you, you really helped me. I now am trying to use webview2 to display videos on the page.
    – Clara2022
    Commented May 11, 2022 at 2:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.