A dependency property is a special type of property which can be set inside a XAML file. Common .Net properties cannot be used in XAML.
This is an example of a dependency property along with a common .Net property wrapper which usually is used to access the dependency property inside your .NET class object.
public Orientation Orientation
{
get { return (Orientation)GetValue(OrientationProperty); }
set { SetValue(OrientationProperty, value); }
}
public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register(
"Orientation", typeof(Orientation), typeof(AnimatedItemsScrollViewer), new PropertyMetadata(Orientation.Horizontal));
Features of dependency properties:
- can be bound to a view model via data binding
- can be set in xaml
- can be set via a style
- can be animated (Hint: animation can only be applied to dependency properties, common properties cannot be animated!)
Hint: Dependency properties can only be defined in classes which derive from DependencyObject (directly or indirectly). All WPF UI Elements derive from DependencyObject.