Binding to List <object> in Silverlight Problem

Can anyone suggest what I'm doing wrong? Basically, I have list items when an item is added to the list. I am dumping the collection into the viewmodel property. The only way I can get it to work is to exclude the member object before reassigning the binding. Any suggestions for updating the user interface when adding an item to the list?

  public List<Item> RegisteredItems { get { return m_vRegisteredItems; } set { m_vRegisteredItems= null; NotifyPropertyChanged("RegisteredItems"); m_vRegisteredItems= value; NotifyPropertyChanged("RegisteredItems"); } } 
+4
source share
2 answers

Use ObservableCollection <T> instead of the <T> list. ObservableCollection <T> implements the INotifyCollectionChanged interface, which allows Silverlight to track changes to the collection.

+7
source

Make sure your collection implements INotifyCollectionChanged . ObservableCollection<T> does this for you.

If you replace List<Item> with ObservableCollection<Item> , this will just work.

In addition, you should not "set" your list - you just need a getter if you do not modify the entire list.

+3
source

Source: https://habr.com/ru/post/1305366/


All Articles