gpt4 book ai didi

c# - 当前上下文中不存在 OnPropertyChange?

转载 作者:太空狗 更新时间:2023-10-29 22:26:49 24 4
gpt4 key购买 nike

似乎看不出我哪里出错了? OnPropertyChange 没有被重新认可有什么建议吗?

  public class MedicationList : INotifyPropertyChanged 
{



public int MedicationID { get; set; }

public string Description
{
get
{
return Description;
}
set
{
OnPropertyChanged( "Description" );
Description = value;

}
}
}

编辑 我添加了public class MedicationList : INotifyPropertyChanged

最佳答案

你应该实现 INotifyPropertyChanged接口(interface),其中声明了单个 PropertyChanged 事件。如果某些对象的属性发生变化,您应该引发此事件。正确实现:

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

关于c# - 当前上下文中不存在 OnPropertyChange?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17885923/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com