OnPropertyChange does not exist in the current context?
You should implement INotifyPropertyChanged interface, which has single PropertyChanged
event declared. You should raise this event if some of object's properties changed. Correct implementation:
public class MedicationList : INotifyPropertyChanged
{
private string _description; // storage for property value
public event PropertyChangedEventHandler PropertyChanged;
public string Description
{
get { return _description; }
set
{
if (_description == value) // check if value changed
return; // do nothing if value same
_description = value; // change value
OnPropertyChanged("Description"); // pass changed property name
}
}
// this method raises PropertyChanged event
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null) // if there is any subscribers
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
I bet you want to do something like this:
public class MedicationList : INotifyPropertyChanged {
public int MedicationID { get; set; }
private string m_Description;
public string Description {
get { return m_Description; }
set {
m_Description = value;
OnPropertyChanged("Description");
}
}
private void OnPropertyChanged(string propertyName) {
if (string.IsNullOrEmpty(propertyName))
throw new ArgumentNullException("propertyName");
var changed = PropertyChanged;
if (changed != null) {
changed(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}