【发布时间】:2011-05-24 10:41:43
【问题描述】:
我有一个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 接口,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;
}
【问题讨论】:
-
请发布您的 xaml 绑定并添加您的集合未正确更新的操作。
标签: c# wpf data-binding