Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This helped me understand the reasoning:</p> <p>The main difference is, that the value of a normal .NET property is <strong>read directly</strong> from a <em>private member in your class</em>, whereas the value of a DependencyProperty is <strong>resolved dynamically</strong> when calling the <em>GetValue() method that is inherited from DependencyObject</em>.</p> <p>When you set a value of a dependency property it is not stored in a field of your object, but in a <em>dictionary of keys and values</em> provided by the base class DependencyObject. The key of an entry is the name of the property and the value is the value you want to set.</p> <p>The advantages of dependency properties are as follows:</p> <p><strong>Reduced memory footprint</strong></p> <p>It's a huge dissipation to store a field for each property when you think that over 90% of the properties of a UI control typically stay at its initial values. Dependency properties solve these problems by only store modified properties in the instance. The default values are stored once within the dependency property.</p> <p><strong>Value inheritance</strong></p> <p>When you access a dependency property the value is resolved by using a value resolution strategy. If no local value is set, the dependency property navigates up the logical tree until it finds a value. When you set the FontSize on the root element it applies to all textblocks below except you override the value. </p> <p><strong>Change notification</strong></p> <p>Dependency properties have a built-in change notification mechanism. By registering a callback in the property metadata you get notified, when the value of the property has been changed. This is also used by the databinding.</p> <p>From: <a href="http://www.wpftutorial.net/DependencyProperties.html" rel="noreferrer">WPF Tutorials</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload