How I Can Refresh ListView in WPF

后端 未结 5 453
死守一世寂寞
死守一世寂寞 2020-12-05 17:37

Hi I am using WPF and adding records one by one to the listview.ItemsSource. My data will appear when all the data is included, but I want to show the data as it is added o

5条回答
  •  一生所求
    2020-12-05 18:23

    Example:

    // Create a collection of Type System.Collections.ObjectModel.ObservableCollection
    // Here T can be anything but for this example, we use System.String
    ObservableCollection names = new ObservableCollection();
    
    // Assign this collection to ItemsSource property of ListView
    ListView1.ItemsSource = names;
    
    // Start adding items to the collection
    // They automatically get added to ListView without a need to write any extra code
    names.Add("Name 1");
    names.Add("Name 2");
    names.Add("Name 3");
    names.Add("Name 4");
    names.Add("Name 5");
    
    // No need to call ListView1.Items.Refresh() when you use ObservableCollection.
    

提交回复
热议问题