How to consume INotifyPropertyChanged events

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?
 
J

Julia M

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?
 
B

Bill McCormick

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
 
J

Julia M

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();
}

?
 
B

Bill McCormick

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top