Why is ReadOnlyObservableCollection.CollectionChanged not public?

后端 未结 8 2101
心在旅途
心在旅途 2021-01-31 06:50

Why is ReadOnlyObservableCollection.CollectionChanged protected and not public (as the corresponding ObservableCollection.CollectionChanged is)?

What is the use of a col

8条回答
  •  醉梦人生
    2021-01-31 07:34

    You might vote for the bug entry on Microsoft Connect that describes this issue: https://connect.microsoft.com/VisualStudio/feedback/details/641395/readonlyobservablecollection-t-collectionchanged-event-should-be-public

    Update:

    The Connect portal has been shutdown by Microsoft. So the link above does not work anymore.

    My Win Application Framework (WAF) library provides a solution: ReadOnlyObservableList class:

    public class ReadOnlyObservableList 
            : ReadOnlyObservableCollection, IReadOnlyObservableList
    {
        public ReadOnlyObservableList(ObservableCollection list)
            : base(list)
        {
        }
    
        public new event NotifyCollectionChangedEventHandler CollectionChanged
        {
            add { base.CollectionChanged += value; }
            remove { base.CollectionChanged -= value; }
        }
    
        public new event PropertyChangedEventHandler PropertyChanged
        {
            add { base.PropertyChanged += value; }
            remove { base.PropertyChanged -= value; }
        }
    }
    

提交回复
热议问题