Answer the question
In order to leave comments, you need to log in
How to update a ListBox (WPF) on demand?
Hello!
There is a ListBox which is filled with the data from a DB. Further, if the record was edited in the application, this list must be updated (rebuild it). How to implement it?
Now I'm building a list in a very "simple" way:
var lines = new List<NewsList>();
// Заполняем
// lines.Add
myListBox.DataContext = lines;
Answer the question
In order to leave comments, you need to log in
First, it's better to use an ItemsSource rather than a DataContext. And secondly, instead of List, take ObservableCollection.
+ to what Maxim Vanyushkin wrote Maxim Vanyushkin :D
To catch changes in the objects themselves inside the collection, you need to use BindingList .
And learn WPF MVVM, spend a couple of hours.
Developing Using the Design Pattern...
+ to what Aleksey Pavlov wrote :
If an already existing record is being edited, then the record object must implement INotifyPropertyChanged, then changing this object in any part of the program will cause it to be updated in all places of the UI where it is shown.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question