1
votes

After reading Internals of Dependeny Property in WPF I am wondering how Dependeny Properties are implemented in Silverlight for WP7. For the investigation Reflector and Dlls from xda forum were used.

In WPF:

A DependencyProperty maintains a static reference of all the DependencyProperty you register in WPF object hierarchy. It maintains a HashTable named PropertyFromName which it uses internally to get the DependencyProperty object. So in other word, each dependencyProperty object is registered in a global HashTable.

In Silverlight for WP7 DependencyProperties have almost the same global HashTable (actually it is

static Dictionary<Type, Dictionary<string, DependencyProperty>> _registeredProperties 

)

But after looking through the source code of the GetValue and SetValue methods of the DependencyObject class I see that _registeredProperties is not used at all.

Does anybody know why it is implemented in such a way? Or maybe I've missed anything? Thank you in advance.

1

1 Answers

2
votes

I think you're missing something indeed. The _registeredProperties dictionary (and whichever equivalent it has in WPF) is used to retrieve a dependency property by its name. It's used mainly for the binding mechanism (where the framework has to retrieve the DP from an expression like {Binding Path=PropertyName}).

When you're in GetValue or SetValue, you already have a reference to the DP (it's the first parameter of the method). Therefore, _registeredProperties is useless there. GetValue and SetValue both use another dictionary, _valueTable, of type Dictionary<DependencyProperty, EffectiveValueEntry>. _valueTable is the actual collection associating a value to a DP.