There is a property, it’s named ImageFullPath1
public string ImageFullPath1 {get; set; }
I’m going fire an event whenever its value changed. I am aware of changing INotifyPropertyChanged, but I want to do it with events.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
INotifyPropertyChangedinterface is implemented with events. The interface has just one member,PropertyChanged, which is an event that consumers can subscribe to.The version that Richard posted is not safe. Here is how to safely implement this interface:
Note that this does the following things:
Abstracts the property-change notification methods so you can easily apply this to other properties;
Makes a copy of the
PropertyChangeddelegate before attempting to invoke it (failing to do this will create a race condition).Correctly implements the
INotifyPropertyChangedinterface.If you want to additionally create a notification for a specific property being changed, you can add the following code:
Then add the line
OnImageFullPathChanged(EventArgs.Empty)after the lineOnPropertyChanged("ImageFullPath").Since we have .Net 4.5 there exists the
CallerMemberAttribute, which allows to get rid of the hard-coded string for the property name in the source code: