c# - Extenion Method for ObservableCollection -


I am trying to add the Accionation Method to ObsavableCollection which will help all < Code> Delete Collection Delete Customers Here is the code HOwever I get some error because I am unable to access GetInvocationList from CollectionChanged.

How can I do this?

  Public Static Zero RemoveCollectionChanged & lt; T & gt; (This overviewCLT; T & gt; COLLECTION) {NotifyCollectionChangedEventHandler_event = collection.CollectionChanged; If (_event! = Null) {foreach (NotifyCollectionChangedEventHandler in Handler Collection, selectGong.GetInvocationList ()) {if (object.ReferenceEquals (Handler. Target, archive)) {CollectionChanged - = Handler; }}}}  

Is there any alternative to achieving this?

You can not access the orientation list of any event list from outside the classroom.

What you can do is wrap the original collection and maintain the event within this class:

  MyObservableCollection & LT; T & gt; : Collections & lt; T & gt;, INotifyCollectionChanged, INotifyPropertyChanged {Observation Collection & lt; T & gt; Internal Compilation = New Observational Collection & lt; T & gt; (); // Apply Collection Methods as Next to Internal Compilation, Change Event Event Leave Event NotifyCollection ChangedEventHandler CollectionChanged; Public MyObservableCollection () {internalCollection.CollectionChanged + = (s, e) = & gt; Collection changed (S, E); }}  

Then you can use the invention list in your custom collection (just not the basic pattern, "Production Code"!).

But I just noticed that the event has been marked as virtual , so it works even easier (not tested, as never done):

  MyObservableCollection & lt; T & gt; : Observable collection & lt; T & gt; {Private list & lt; NotifyCollectionChangedEventHandler & gt; Changehands = new list & lt; NotifyCollectionChangedEventHandler & gt; (); Public override event NotifyCollectionChangedEventHandler store changed {add {changedHandlers.Add (value); Base.CollectionChanged + = Value; } Remove {changedHandlers.Remove (value); Base.CollectionChanged - = Value; }} Public Zero RemoveCollectionChanged () {foreach (Change handlers in var handler) base.CollectionChanged - = Handler; ChangedHandlers.Clear (); }}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -