Reputation: 3443
I'm a bit new to MVVM, and was wondering
Let's say I have defined a ObservableCollection<Differences> Diffs
property.
I also have the following property:
public bool IsSame
{
get
{
return Diffs.Count == 0;
}
}
I dont get how I'm supposed to implement the OnPropertyChanged
for IsSame
, because it is implicit from the Diff list.
OnCollectionChanged
event and then check if it changes IsSame
? OnCollectionChanged
?Thank you very much.
Upvotes: 1
Views: 190
Reputation: 273784
Should I use a backing field anyway and handle the List OnCollectionChanged?
To do it correctly: Yes.
When related properties change it's up to the source to raise all events. Your main problem here is to detect when IsSame
actually changes (ie goes from 1 to 0 or from 0 to 1). You need either a backing field or you will raise the event (much) more often then is required.
Upvotes: 3
Reputation: 22445
when ever you collection changes you should call OnPropertyChanged("IsSame"); - thats right. but when to call depends on your viewmodel logic.
edit: assume that you have an Add and Remove command, then you have to call OnPropertyChanged("IsSame"); within these methods.
Upvotes: 1