c# - Combine List and ObservableCollection -


i have wpf application contains datagrid bound list. list implements inotifypropertychanged interface. can see when property has changed. when new item added or deleted there no event tell me has happened.

after reading have seen observablecollection can tell me when item has been added or deleted via collectionchanged event. observablecollection has few short comings list overcomes.

so question if it's possible combine list & observablecollection have functionality of both? possible have list inherit from? if there methods need overwritten?

the simple answer question 'yes, work'.

the observablecollection<t> class extends collection<t> class, implements ilist<t>, icollection<t>, ienumerable<t>, ilist, icollection, ienumerable interfaces - same list<t> class. however, observablecollection<t> class implements inotifycollectionchanged , inotifypropertychanged interfaces, these main difference between two.

therefore extend list<t> class , manually implement inotifycollectionchanged , inotifypropertychanged interfaces best of both worlds. having said that, after manually adding addrange , sort methods custom observablecollection<t> base class, have never felt need use list<t> display objects in of wpf projects.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -