How can I make a read-only ObservableCollection property?

前端 未结 5 1647
你的背包
你的背包 2021-01-03 17:55

I\'d like to expose a property on a view model that contains a list of objects (from database).

I need this collection to be read-only. That is, I want to prevent A

5条回答
  •  轮回少年
    2021-01-03 18:17

    Use ReadOnlyObservableCollection< T >

    public ReadOnlyObservableCollection ReadOnlyFoo
    {
        get { return new ReadOnlyObservableCollection (_CollectionOfFoo); }
    }
    

    As has been pointed out, please use Eric J's answer as this one mistakenly is returning a new instance every time.

提交回复
热议问题