Update automatic ListBox items when alter List

前端 未结 3 1471
南旧
南旧 2021-01-27 07:16

I have a ListBox, I populate it with ItemsSource with List.

But when I delete or add new control for this List, I need every tim

3条回答
  •  清歌不尽
    2021-01-27 08:10

    Instead of using a List, use an ObservableCollection. It is a list that supports change notifications for WPF:

    // if this isn't readonly, you need to implement INotifyPropertyChanged, and raise
    // PropertyChanged when you set the property to a new instance
    private readonly ObservableCollection items = 
        new ObservableCollection();
    
    public IList Items { get { return items; } }
    

提交回复
热议问题