I have a very simple class that has a single property and which inherits INotifyPropertyChanged:
class SimpleClass:INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _property;
public string Property
{
get { return _property; }
set
{
_property = value;
PropertyChanged(this, new PropertyChangedEventArgs"Property"));
}
}
}
I try to instantiate a SimpleClass object in the constructor for a WPF Window but I get the following TargetInvocationException: “Exception has been thrown by the target of an invocation”.
If I remove the INotifyPropertyChange inheritance (and any reference to the PropertyChanged event) then I don’t get the error and my project runs without any problems. Any ideas why?
Cheers
You aren’t checking for null on
PropertyChanged.if nobody is listening, then it will be null. most people protect for the event listeners to change during the event, as well: