I read Dependency properties for several days and understand how they retrieve the value, rather than set / get them as in the CLR properties. Feel free to correct me if I am wrong.
From my understanding, all WPF controls, such as TextBlock, Button, etc. that are derived from DependencyObject will also contain dependency properties to store their values instead of using CLR properties. This has the advantage of overriding local values when using animations or inheriting values, if the local value is not set at all, etc.
Now I'm trying to come up with some examples for creating and using my own dp.
1) Can I create my own dependency property for an existing WPF control? Suppose I need a dependency property of type integer in a WPF Textblock class? Or do I need to create a new class derived from TextBlockBase to create my dependency property above?
2) In any case, let's say I created a dependency property in a WPF text block class. Now I would like to use it, linking the contents of the label with this TextBlock dependency property. So that the label always displays the actual TextBlock dp value, regardless of whether it is inherited or set locally.
Hope someone can help me with these two examples ... Thanks a lot, Kava
Houman
source share