Collection properties should be read only

前端 未结 2 1062
陌清茗
陌清茗 2021-01-14 08:10

I am using FxCop for my WPF MVVM assembly and it gives me the error

Collection properties should be read only

But in my propert

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-14 08:48

    You should rarely need to raise a PropertyChanged event on a collection. Make the collection observable so that it notifies any bindings whenever items are added or removed:

    public IList Employees
    {
        get; 
        private set;
    }
    
    // in your constructor:
    this.Employees = new ObservableCollection();
    

提交回复
热议问题