My previous similarly related question was answered through using INotifyPropertyChanged
. However, researches taught me that inheriting ViewModelBase
from GalaSoft.MvvmLight is similar with INotifyPropertyChanged
.
I was using this answer from my question in changing data in every item in ObservableCollection
. But I don't want use INotifyPropertyChanged
anymore since I am already inheriting ViewModelBase
. Codes below are some that I added from the answer I already mentioned:
Food class
private bool _isAllSelected = true;
public bool IsAllSelected
{
get
{
return _isAllSelected;
}
set
{
Set(IsAllSelected, ref _isAllSelected, value);
// send message to viewmodel
Messenger.Default.Send(Message.message);
}
}
ViewModel class
// message handler
private void MsgHandler(Message message)
{
RaisePropertyChanged(SelectAllPropertyName);
}
// the property that change all checkbox of fruits
public const string SelectAllPropertyName = "SelectAll";
public bool SelectAll
{
set
{
bool isAllSelected = Foods.Select(c => c.IsAllSelected).Any();
foreach (var item in Foods.SelectMany(c => c.Fruits).ToList())
{
item.IsSelected = isAllSelected;
}
}
}
// receives message function, called at the start
public void Receiver()
{
Messenger.Default.Register<Message>(this, MsgHandler);
}
Problem here is this is not working like it was previously using INotifyPropertyChanged
.