How to consume INotifyPropertyChanged events

  • Thread starter Thread starter Bill McCormick
  • Start date Start date
B

Bill McCormick

I have a class that implements INotifyPropertyChanged. Parts of a UI are
bound to it, and they work as expected. However, how can I be notified of
certain property changing events without binding to it, so that I don't need
to create new event handlers?
 
I have a class that implements INotifyPropertyChanged. Parts of a UI are
bound to it, and they work as expected. However, how can I be notified of
certain property changing events without binding to it, so that I don't need
to create new event handlers?

What exactly are you trying to accomplish?
Wouldn't the setter suffice?
 
What exactly are you trying to accomplish?
Wouldn't the setter suffice?
When a property changes, the PropertyChanged PropertyChangedEventHandler is
called. I'd like to *hook* into that in the same way a binding consumer
object does so that I don't need to create separate events.

Thanks,

Bill
 
When a property changes, the PropertyChanged PropertyChangedEventHandler is
called. I'd like to *hook* into that in the same way a binding consumer
object does so that I don't need to create separate events.

Have you tried

MyClass c = new MyClass();
c.PropertyChanged += OnPropertyChanged;
void OnPropertyChanged(object sender,
System.ComponentModel.PropertyChangedEventArgs e)
{
throw new NotImplementedException();
}

?
 
Have you tried

MyClass c = new MyClass();
c.PropertyChanged += OnPropertyChanged;
void OnPropertyChanged(object sender,
System.ComponentModel.PropertyChangedEventArgs e)
{
throw new NotImplementedException();
}

?

Yes, thanks, I guess that's what I'm looking for. Except, since that would
get called for every property change and you'd need to check for which
property changed,

if(e.PropertyName == "TheOneProperty") {}


I think it's more efficient to fire off new events when the property of
interest actually does change.


Do you happen to know what the difference is between

c.PropertyChanged += OnPropertyChanged;

and

c.PropertyChanged += new
System.ComponentModel.PropertyChangedEventHandler(OnPropertyChanged);


Thanks,

Bill
 
Back
Top