views:

819

answers:

1

In WPF:

Can someone please explain the relationship between DependencyProperty and Databinding?

I have a property in my code behind I want to be the source of my databinding. When does a DependencyProperty (or does it) come into play if I want to bind this object to textboxes on the XAML.

+6  A: 

The target in a binding must always be a DependencyProperty, but any property (even plain properties) can be the source.

The problem with plain properties is that the binding will only pick up the value once and it won't change after that because change notification is missing from the plain source property.

To provide that change notification without making it a DependencyProperty, one can:

  1. Implement INotifyPropertyChanged on the class defining the property.

  2. Create a PropertyNameChanged event. (Backward compatibility.)

WPF will work better with the first choice.

Joel B Fant
Thank you, exactly the answer I was looking for.
mrbradleyt