In the loop I create n-buttons, and by clicking on each button, the data in the listView should be added. The code works, but the UI itself is not updated for some reason.

List<Bludo> cash = new List<Bludo>(); Button btn = new Button(); btn.Click += delegate { Bludo bl = new Bludo(); var data = btn.Tag.ToString().Split(';'); bl.tsena = Convert.ToDouble(data[0]); bl.bludo = data[1]; cash.Add(bl); listView.ItemsSource = cash; listView.UpdateLayout(); }; 
  • one
    What kind of cash ? If it is not an ObservableCollection , it will not work. - VladD

1 answer 1

Instead of List use ObservableCollection , it is inherited from INotifyCollectionChanged , which in WPF is intercepted as a collection change, but if you need to use the List , you can inherit from it and INotifyCollectionChanged by overriding the insert / delete methods