This is an old revision of the document!


Dependency Properties

If data binding to certain properties is required, then these need to be implemented as Dependency Properties.

Here is a good example (from: C# is Easy: Dependency Property):

public class Button : ButtonBase
{
// The dependency property
public static readonly DependencyProperty IsCancelProperty;
static Button()
{
// Register the property
Button.IsCancelProperty = DependencyProperty.Register(“IsCancel”,
typeof(bool), typeof(Button),
new FrameworkPropertyMetadata(false,
new PropertyChangedCallback(OnIsDefaultChanged)));}
// A .NET property wrapper (not must)
public bool IsCancel
 
{
get { return (bool)GetValue(Button.IsCancelProperty ); }
set { SetValue(Button.IsCancelProperty , value); }
}
// A property changed callback (not must)
private static void OnIsCancelChanged(
DependencyObject o, DependencyPropertyChangedEventArgs e) {}}