Pages

Your Ad Here

Saturday, 2 October 2010

Dependency Property in WPF.

public static readonly DependencyProperty MaskProperty =
DependencyProperty.Register("Mask", typeof(string), typeof(PTextBox), new PropertyMetadata(null));

public string Mask
{
get { return (string)GetValue(MaskProperty); }
set { SetValue(MaskProperty, value); }
}

First section explains about Dependency property. It is a static property. In old ways, Void was used to override the property, but without overriding we can reuse the same property.
“
In the "old ways", to set up some sort of change notification on the Height property here, you would have had to override it in a new class deriving from this FrameworkElement class and added whatever you needed in the 'set' part of the property here. However, you no longer have to do things like that. Instead, you can use Dependency properties.”

Eg: Mask is the property present in PTextBox class with type string. So first MaskProperty is created as DependencyProperty.

Then Mask property wrapper is created using GetValue() and SetValue() methods.

::http://www.switchonthecode.com/tutorials/wpf-tutorial-introduction-to-dependency-properties

No comments: