我有一个绑定(bind)到列表框的 ObservableCollection
public ObservableCollection<InsertionVM> Insertions
{
get
{
return _insertions;
}
set
{
_insertions = value;
base.OnPropertyChanged("ChromosomeList");
}
}
它的成员 InsertionVM
实现了 INotifyPropertyChanged。它有一个将被更新的属性。
public bool IsChecked
{
get
{
return _isChecked;
}
set
{
_isChecked = value;
base.OnPropertyChanged("IsChecked");
}
}
即使我为每个属性实现了 INotifyPropertyChanged 接口(interface),为什么 ObservableCollection 不刷新?
更新:
我尝试了下面给出的链接,但“更敏感的集合”仅在删除/添加对象时更新。
if (e.Action == NotifyCollectionChangedAction.Remove)
{
foreach (InsertionVM item in e.NewItems)
{
//Removed items
item.PropertyChanged -= EntityViewModelPropertyChanged;
}
}
else if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (InsertionVM item in e.NewItems)
{
//Added items
item.PropertyChanged += EntityViewModelPropertyChanged;
}
}
public void EntityViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
{
//Debugger does not reach here
}
构造函数:
public ChromosomeVM(Chromosome _chr, string insertionFilePath)
{
Chr = _chr;
_insertions.CollectionChanged += ContentCollectionChanged;
}
最佳答案
这是您的代码:(请同时查看我所做的评论)
public ObservableCollection<InsertionVM> Insertions // propertyName == Insertions
{
get
{
return _insertions;
}
set
{
_insertions = value;
base.OnPropertyChanged("ChromosomeList"); // What is ChromosomeList??
}
}
你现在能看出问题所在了吗?将 ChromosomeList
更改为 Insertions
。希望至少能解决一些问题!
关于c# - 即使实现了 INotifyProperty 接口(interface),ObservableCollection 也不会刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4425352/