That's why it's called the default *value* instead of default *values* [Tip: The default value of a DependencyProperty is shared by all instances of the class that registers it]
Tip
The default value of a DependencyProperty is shared by all instances of the class that registers it
Explanation
The last two tips explained how to set the default value of a Silverlight/WPF DependencyProperty. But there's something you need to be aware of when you're using either technique: the default value of a DependencyProperty is shared by all instances of a class. This doesn't tend to matter for value types, immutable reference types, and sharable types (like brushes), but it affects mutable reference types and can lead to unexpected behavior. The most common scenario is creating a collection-type DependencyProperty (for something like Collection(T)) - the intent is for each instance to have its own unique collection, but because the default value is shared, all instances end up sharing the same list! In such cases, there are two things to change: make the DependencyProperty read-only (with RegisterReadOnly) and initialize the property in the class constructor. [Didn't a previous tip say that was bad? Yes, but this scenario is special.
Good Example
public Collection<string> MyStringCollection { get { return (Collection<string>)GetValue(MyStringCollectionProperty); } } protected static readonly DependencyPropertyKey MyStringCollectionPropertyKey = DependencyProperty.RegisterReadOnly( "MyStringCollection", typeof(Collection<string>), typeof(MyControl), new PropertyMetadata(null)); public static readonly DependencyProperty MyStringCollectionProperty = MyStringCollectionPropertyKey.DependencyProperty; public MyControl() { SetValue(MyStringCollectionPropertyKey, new Collection<string>()); }
More information