How to update ListView



  • I'm setting up a n-knopok in the cycle, and each button will have to be added in listView. The code works, but the UI itself is not being 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();
    
                        };
    



  • For List Use it. https://msdn.microsoft.com/ru-ru/library/ms668604(v=vs.110).aspx he inherits from INotifyCollectionChangedwhich is intercepted in WPF as a change of collection, but if you need to use it ListYou can inherit from him and INotifyCollectionChangedby redefining the methods of insertion/depositioning




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2