I generate objects of framework Rectangle class (which is sealed) and programmatically add them to Canvas. I want to add some information to that objects. Is there such a possibility? I can get and set attached properties in XAML but these is not useful for me.
Get and set WPF custom attached property from code behind
Asked Answered
Take a look at Custom Attached Properties. –
Lacteous
@ Clemens, if I wrote that I can get and set this property in XAML it means that I can properly register it. –
Gummy
The section from Clemens link that describes how to do this in code is at: Section "Attached Properties in Code". This is similar to the accepted answer, with additional explanation. –
Stormystorting
You can set attached properties in code, something like this:
OwningClass.SetMyAttachedProperty(textBox, true);
It's good for any "attached property", presuming you declare it in the standard way. Here's an example of me using a custom one in code: github.com/ButchersBoy/MaterialDesignInXamlToolkit/blob/master/… –
Twelvemonth
© 2022 - 2024 — McMap. All rights reserved.