I created a user control with one DP.
Now am using that UC in my page with 5 times and my question is, DP is a static property so it will create only one instance.Now how the value will be hold for 5 different controls?
I created a user control with one DP. Now am using that UC in
Share
Dependency properties are created per type and can be customized if required. So if your screen has, let say, 20 buttons yours storage space for properties occupied is as good as for one button.
DependencyObject maintains two HashTable members:
Static member stores the default values of DP (only one for all types) and non-static member stores values those have changed.
When you call the SetValue method of your dp you are basically adding an item in your non-static HashTable. And when GetValue is called DependencyObject first checks if non-static HashTable has the key; if found then returns the value else it returns the value from static member (which is the default value)
So,
DP does not hold any value till the time it’s changed.
DP are static so that your app can observe their values; that’s why you register a DP instead of instantiate.
DP holds value in a HashTable declared in DependencyObject class, you need to pass the type of the owner while registering one.
You can also see it here on my blog: How Dependency Property holds value