If you, like me, purchased the Windows Application Development Cookbook and are working through the examples you may find that you get an error on the Introducing Bindings and commands in the MVVM and Data Binding section.
Suppression State Error CS0619 ‘ImplementPropertyChangedAttribute’ is obsolete: ‘This configuration option has been deprecated. The use of this attribute was to add INotifyPropertyChanged to a class with its associated event definition. After that all classes that implement INotifyPropertyChanged have their properties weaved, weather they have the ImplementPropertyChangedAttribute or not. This attribute was often incorrectly interpreted as an opt in approach to having properties weaved, which was never the intent nor how it ever operated. This attribute has been replaced by AddINotifyPropertyChangedInterfaceAttribute.’
The error is somewhat self explanatory and the answer is right there in the text but it wasn’t immediately clear to me, a MVVM novice, on how to fix it. So after a little Googling and some trial and error I was able to finish the recipe by changing the
in the recipe to
While that worked for the sample in the book I didn’t think that was the correct (or complete) answer. So I did a little more experimenting and found that if I commented out the attribute above the class name and added INotifyPropertyChanged to the end of the class name it also worked.
public class MainViewModel : INotifyPropertyChanged
I have no idea of the differences between the two or if I am still doing something wrong but the second one feels like the correct version because it fits the more common model I have seen in sample code.
If you know the difference between the two or what the more correct modification is please leave a comment because I would really like to understand the differences. I have did a little searching on my own but couldn’t find anything definitive.
Oh and don’t forget to add the following to the page.
public event PropertyChangedEventHandler PropertyChanged;
Updated 10/29/2017 – I found this post on Stack Overflow with more information about this subject.