我有一個ObservableCollection在我的ViewModel與INotifyPropertyChanged
,說A.現在我要循環通過A獲取一些元素更新。更新ObservableCollection元素不工作
public ObservableCollection<ClassA> A
{
get
{
if (this.a== null)
{
this.a= new ObservableCollection<ClassA>();
}
return this.a;
}
set
{
this.a= value;
this.OnPropertyChanged("A");// implement PropertyChangedEvent
}
}
在循環中,我更新了值。
foreach (var item in MyViewModel.A)
{
if(condition)
MyViewModel.A.Type= "CASH";
else
MyViewModel.A.Type= "CHECK";
}
但我看到setter部分沒有達到。所以收集不會更新。
不,我做到了。 ClassA已經實現了INotifyPropertyChanged。 – Bigeyes
好的。建議看看這個[問題](http://stackoverflow.com/questions/1427471/observablecollection-not-noticing-when-item-in-it-changes-even-with-inotifyprop)。他們似乎在做與你類似的事情。 –
我試過了。它不能很好地工作,因爲它包含ADD/REMOVE。我想替換部分代碼。 – Bigeyes