INotifyPropertyChanged- WPF

A very common and popular way to synchronize data between the model and the view in WPF is using DataBinding. The value of the model is transferred to the view once, when the binding is initialized. But for every subsequent change, the model must notify the binding to transfer the value again. This is done by implementing the INotifyPropertyChangedinterface on the model.

In the setter of every bound property there must be some code to raise the PropertyChanged event, passing the name of the modified property as a string. This has some disadvantages:

  • You cannot use Auto-properties
  • The property name is passed as a string. This brings ugly errors, when you forgot to change the string after a rename.
  • Every property needs extra code

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s