I implement INotifyPropertyChanged in the base class as follows:
public class NotifyPropertyChangedBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected virtual void RaisePropertyChanged(string propertyName) { var propChangedHandler = PropertyChanged; if (propChangedHandler != null) { var args = new PropertyChangedEventArgs(propertyName); propChangedHandler(this, args); } } }
I use it as follows:
RaisePropertyChanged("Name");
I get a NullReferenceException, while the arguments to "this" and the handler are NOT null. Can anyone shed some light on this?
Thanks.
-> Full exception stacking: http://pastebin.com/bH9FeurJ
UPDATE An exception occurs when I overwrite an instance of a class that contains this property. A simplified example:
public class Person : INotifyPropertyChanged { private string _name; public string Name { get { return _name; } set { _name = value; RaisePropertyChanged("Name"); } }
-snip -
public class ViewModel { private Person _dummyPerson; public Person DummyPerson { get { return _dummyPerson; } set { _dummyPerson = value; RaisePropertyChanged("DummyPerson"); } } public void Foo() { DummyPerson = new DummyPerson();
-snip -
I use this DummyPerson property and its Name to bind data to the user interface. After this, the second and all subsequent attempts will result in a NullReferenceException .
source share