Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is dependency property implemented?

Can anyone explain how is dependency property implemented? Is it just a static dictionary that is declared in base class with a reference of given instance as a key?I can't find any resources about this in internet...
Thanks a lot

like image 665
Arsen Mkrtchyan Avatar asked May 19 '09 04:05

Arsen Mkrtchyan


People also ask

How does dependency property work?

A dependency property can reference a value through data binding. Data binding works through a specific markup extension syntax in XAML, or the Binding object in code. With data binding, determination of the final property value is deferred until run time, at which time the value is obtained from a data source.

How does dependency property work internally?

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.

What is the biggest feature of dependency property?

Arguably the biggest feature of a dependency property is its built-in ability to provide change notification. The motivation for adding such intelligence to properties is to enable rich functionality directly from declarative markup.


2 Answers

I see two questions:

  1. How do dependency properties work? The MSDN article on Properties in WPF is a great series on dependency properties. Should be a good overview to get you started.
  2. How are dependency properties implemented? You won't find any resources on this because why would Microsoft want to expose their implementation of DP? That being said, that's certainly open to discussion.
like image 88
Szymon Rozga Avatar answered Sep 19 '22 16:09

Szymon Rozga


...a few years later.

and there is already a source code browser for .NET. You can study how it is implemented here: DependencyProperty.cs

like image 22
t3chb0t Avatar answered Sep 18 '22 16:09

t3chb0t