Listbox bound to an ObservableCollection doesn't update

后端 未结 3 1130
难免孤独
难免孤独 2020-12-21 07:36

I am using a ObservableCollection to store the Environment Variables of Windows.

class VariableVieWModel
{
    ObservableCollection vars         


        
3条回答
  •  天涯浪人
    2020-12-21 08:07

    You haven't modified the ObservableCollection, only replaced it. You should implement INotifyPropertyChanged and call PropertyChanged in the Variables property setter.

    BTW it's common in MVVM implementations to have a base class for your ViewModel:

    class VariableViewModel : ViewModelBase
    

    and implement common functionality such as INotifyPropertyChanged in the base class to avoid duplication of code.

提交回复
热议问题