WPF:Dependency Property


Dependency property of WPF is quite similar to normal .NET properties, but the concept behind is much more complex and powerful.
Dependency properties are used when the resolution of a property's value is based on other properties or runtime settings (such as operating system settings). 

// Dependency Property
public static readonly DependencyProperty
CurrentTimeProperty =
DependencyProperty.Register( "CurrentTime", typeof(DateTime
),
typeof(MyClockControl), new FrameworkPropertyMetadata(DateTime
.Now));

// .NET Property wrapper
public DateTime CurrentTime
{
get { return (DateTime
)GetValue(CurrentTimeProperty); }
set { SetValue(CurrentTimeProperty, value
); }
}
 
The difference between both the property is that: the value of a normal .NET property is read directly from a private member in your class, whereas the value of a DependencyProperty is resolved dynamically when calling the GetValue() method that is inherited from DependencyObject.

The advantages of Dependency property are:

1. Reduced memory footprint
2. Value inheritance
3. Change notification
Ebook Download
View all
Learn
View all
F11Research & Development, LLC