Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove from list doen't call setter?

Tags:

c#

mvvm

In my c# app (MVVM Pattern) I have something like this:

 private List<MyClass> _classes= new List<MyClass>();
 public List<MyClass> Classes
    {
        get { return _classes; }
        set
        {
            _servers = value;
            NotifyOfPropertyChange(() => Classes);
            NotifyOfPropertyChange(() => Classes2);
        }
    }
  public List<MyClass> Classes2
    {
        get
        {
           return Classes.Where(class=> class.boolValue).ToList();
        }
    }

And when I use Classes.Add(class) or Classes.Remove(class) setter doesn't called. Why?

like image 270
jimpanzer Avatar asked Dec 20 '22 05:12

jimpanzer


1 Answers

Because you aren't changing the Classes property -- you are changing the internal state of the object referenced by Classes. If you need to be notified of changes to the list, you may want to look into ObservableCollection:

http://msdn.microsoft.com/en-us/library/ms668604.aspx

like image 189
wgraham Avatar answered Jan 03 '23 18:01

wgraham