Understanding WPF Dependency Properties is a bit confusing when first learning WPF. The confusion arises if you assume that Dependency Property's work the same as C# or Visual Basic properties. Once you understand that Dependency Properties don't use local storage for the Property backing data, but instead entrust that responsibility to the Dependency System you are on your way to learning the Zen of WPF. To tap into the power of Dependency Properties you have to register your property with the Dependency System.
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
Once registered, as shown above, you have a property called HighlightBrush which you can use in your XAML.
Providing a default value for a.NET property makes sense in certain circumstances and it is reasonable feature to have in WPF Dependency Property's too. So let's learn a little more about how default values work in WPF Dependency Properties.
For this example we'll look at the ProgressBar.Maximum property. It has a default value of 100, which I found by spending a few minutes probing the WPF API with the RedGate Reflector tool (http://www.red-gate.com/products/reflector/).
Here is a simplified version of the registration code for the Maximum property.
At runtime, the Dependency System uses an evaluation algorithm to determine what the current value is for a Dependency Property. The default value is returned, if no other item is affecting the property. Plenty of other factors can influence what the Dependency System returns. For example a running animation, active data-binding or a WPF style could alter the current value for the Maximum property.
Let's look at more XAML; this example creates a few ProgressBars.
In the C# we can check the value.
Determining the original default
If the default value has been change directly, by modifying the property in XAML or setting the property in code, you have dig a little to determine the original default value.
Here are some examples.