OnPropertyChange并不在当前上下文中是否存在? [英] OnPropertyChange does not exist in the current context?
本文介绍了OnPropertyChange并不在当前上下文中是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎无法看到我错了?该OnPropertyChange没有被recondnised任何建议。
Cant seem to see where I am going wrong? the OnPropertyChange is not being recondnised any suggestions?
public class MedicationList : INotifyPropertyChanged
{
public int MedicationID { get; set; }
public string Description
{
get
{
return Description;
}
set
{
OnPropertyChanged( "Description" );
Description = value;
}
}
}
}
}
的修改的我已经加入公共类MedicationList:INotifyPropertyChanged的
推荐答案
您应该实施的 INotifyPropertyChanged的接口,它有一个的PropertyChanged
事件声明。如果某些对象的属性改变,你应该引发此事件。正确执行:
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));
}
}
这篇关于OnPropertyChange并不在当前上下文中是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文