Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PropertyChanged.Fody and PropertyObserver

Tags:

c#

wpf

Both Fody's PropertyChanged and Josh Smith's PropertyObserver are two great packages/patterns to use in WPF development. However, they don't seem to be able to be used together.

At compile time, it seems that the class that I'm trying to observe needs to explicitly implement INotifyPropertyChanged (instead of just adding the Fody ImplementPropertyChanged tag on the class).

The type 'MyViewModel' cannot be used as type parameter 'TPropertySource' in the generic type or method 'PropertyObserver'. There is no implicit reference conversion from 'MyViewModel' to 'System.ComponentModel.INotifyPropertyChanged'

Am I missing something? Does someone have a clever solution?

like image 735
Darlene Avatar asked Sep 28 '22 05:09

Darlene


1 Answers

As the Fody.PropertyChanged documentation states:

All classes that do not have [ImplementPropertyChanged] but still have INotifyPropertyChanged will have notification code injected into property sets.

So manually implement INotifyPropertyChanged on your class (no choice here, since PropertyObserver is expecting a type implementing this interface), and you'll still have the the calls to PropertyChanged injected in your properties by Fody.

like image 192
Kevin Gosse Avatar answered Oct 12 '22 17:10

Kevin Gosse