WinUI3: How to override metadata for a dependency property

Minh Van 171 Reputation points
2023-02-01T04:52:17.29+00:00

Hi,

I got a class called CustomTextBox which inherits from TextBox.

How can I override an event when the value of "IsReadOnly" property is changed? I want to do something else from code behind when this value is changed.

I have searched online and there is a method called "OverrideMetadata", but it is available in WPF, not WinUI3.

Thanks.

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

Accepted answer
  1. Jeanine Zhang-MSFT 10,536 Reputation points Microsoft Vendor
    2023-02-01T06:51:56.19+00:00

    Hello,

    Welcome to Microsoft Q&A!

    As far as I'm concerned, you couldn't override metadata for "IsReadOnly" property directly, and there is no similar method in winui3.

    I suggest you could try to implement your own dependency properties for "IsReadOnly" property. For more details you could refer to the Doc: Custom dependency properties.

    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.