I did not find any similar question, except for those where changes do not occur when adding an element. And my problem is that there is

public ObservableCollection<Note> Notes {get; set;} 

In the constructor of this class, I initialize this list.

 Notes = new ObservableCollection<Note>(helper.GetChildNodes()); 

And everything is fine. But during the execution of the program, it is necessary to repeat a piece of code that is written above, but at the same time helper.GetChildNodes() already returns other values.

But the list for some reason does not update the binding with ListBox

 <ListBox Grid.Row="1" ItemsSource="{Binding Notes}" DataContext="{Binding}" SelectedItem="{Binding SelectedNote}"> 

What to do? Tell me please!

  • необходимо повторить кусок кода - the entire string Notes = new ObservableCollection<Note>(helper.GetChildNodes()); ? If yes, then this is a mistake, because the binding happens to the object that was created earlier, and you reinitialize it with new . - EvgeniyZ 7:26 pm
  • Hmm I don’t really understand what you mean, but this collection is in the MainViewModel class, which is inherited from BaseViewModel, and it is already from INotifyPropertyChanged. - Pavel Erikov
  • EvgeniyZ and how then to be. I tried to clear the collection and therefore add new values ​​through CopyTo, but nothing happened either. - Pavel Erikov
  • Your Notes should only be initialized once, that's all. Further you do not touch its initialization. Add through .Add() and similar methods. That is, the best option is to go through the helper.GetChildNodes() loop and add each element to Notes . Or make an event through which you will add new objects (again through .Add() . - EvgeniyZ
  • Laaaadnooo. So why CopyTo does not work because 1 time initialization goes. - Pavel Erikov

0