EditCategory
Fundamentals
EditQuestion
How do I declare a DependencyProperty?
EditAnswer
A DependencyProperty should be stored in a public static readonly field. This is to ensure its visibility to anyone wishing to use it.
There is an informal naming convention for the field. Namely, it should be the DependencyProperty's name suffixed with the "Property" token. This convention is the same for all DependencyProperty types (normal, attached, readonly, and attached readonly).
You then need to call the DependencyProperty.Register() function.
In this function, you specify the property's name, type, owner type, default value (if desired) and callbacks (if desired).
Example (with a default value of -125 and no callback):
public CustomClass1: DependencyObject
{
public static readonly DependencyProperty MyCustomProperty = DependencyProperty.Register( "MyCustom",
typeof(int), typeof(CustomClass1), new PropertyMetadata(-125) );
}