Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DependencyProperty and DataBinding?

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.

like image 945
mrbradleyt Avatar asked Oct 01 '08 18:10

mrbradleyt


1 Answers

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.

like image 195
Joel B Fant Avatar answered Oct 23 '22 11:10

Joel B Fant