I've got quite simple problem but gives me a headache and I'm wasting too much time. I've ran out of ideas anyway:) For some reason I can't pass the value of my property variable to my event handler. Here is what I've got , an for me everything is fine but it won't work:(
Any idea why it's not passing the actual value of the variable? Thanks in advance:)
Just as the name suggests,
propertyName
should contain the property's name, not value. Also see PropertyChangedEventHandler and PropertyChangedEventArgs on MSDN for more details.As to why your event handler
null
, I suspect you haven't subscribed to it. You should have something like the following somewhere in your program:then when
obj.Moves
changesobj_PropertyChanged
will be called.I understand your confusion, so let me give a little more explanations. Suppose you have two classes
A
andB
, and you wantB
to be notified when a property ofA
is changed. Then you can makeA
implement INotifyPropertyChanged, and makeB
subscribe to the PropertyChanged event ofA
, like the following:With the above,
B.a_PropertyChanged
will be called wheneverA.Moves
is changed. More precisely, ifb
is an instance ofB
, thenb.a_PropertyChanged
will be called wheneverb.a.Moves
is changed. Also please note how my implementation of the setter ofMoves
differs from yours.