WinUI3 : How to set ID or a Custom property to WinUI3 Window

Harshithraj1871 1,496 Reputation points
2023-02-15T17:06:40.0566667+00:00

Hi,

I'm working on the WinUI3 desktop application. I'm trying to set a custom property and an ID to the winui3 window and get the WinUI3 window back with only the ID. I could not find any way to put an ID or Custom property to WinUI3.

I tried to extract HWND from the WinUI3 window and set the ID and Prop using SetProp, It works well for custom properties but for setting id, it doesn't fit well as per my requirements. I want to get the Window back when I have only the ID, I was able to get back the HWND back when I only had the ID but I was not able to get back the WinUI3 Window from that HWND.

It would be of great help if you could help me with this issue.

Thank you

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
722 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,519 questions
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 11,256 Reputation points Microsoft Vendor
    2023-02-16T09:32:14.2166667+00:00

    Hello,

    Welcome to Microsoft Q&A!

    how do we set a custom ID for Windows in this case?

    AppWindow and Window handle have WindowId.

    how can we get back the winrt::Microsoft::UI::Xaml::Window back from AppWindow

    Win32Interop.GetWindowFromWindowId with AppWindow.Id.

    Thank you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful