WinUI3 : Which is the best way to store an identifier in winui control

Harshithraj1871 1,681 Reputation points
2023-08-07T05:24:13+00:00

Hi,

Im working on the WinUI3 desktop application in c++ without using XAML. I want to store an identifier in winui3 control, and I learned that we could do it with the help of Name property or Tag property.

My identifier is an integer, to store it in the Name property, I will have to convert it to hstring, and to keep it in the tag property I have to box it to inspectible, and to get back the identifier I have to unbox it.

So which is the best way to stare an integer identifier? does boxing and unboxing the value have a significant overhead?

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.
870 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jeanine Zhang-MSFT 11,341 Reputation points Microsoft External Staff
    2023-08-07T07:51:55.91+00:00

    Hello,

    Welcome to Microsoft Q&A!

    I more recommend you use the Name property.

    And according to the Doc: Boxing and Unboxing

    It is best to avoid using value types in situations where they must be boxed a high number of times. Boxing and unboxing are computationally expensive processes.

    Boxing and unboxing the value will have a significant overhead.

    Thank you.

    Jeanine


    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.