As stated here, the PropertyChangedEventManager
class
Provides a WeakEventManager implementation so that you can use the "weak event listener" pattern to attach listeners for the PropertyChanged event.
There are two ways to subscribe for property changes:
void AddHandler (INotifyPropertyChanged source, EventHandler<PropertyChangedEventArgs> handler, string propertyName)
void AddListener (INotifyPropertyChanged source, IWeakEventListener listener, string propertyName)
They both end up calling the same method:
private void AddListener(INotifyPropertyChanged source, string propertyName, IWeakEventListener listener, EventHandler<PropertyChangedEventArgs> handler)
with either listener
or handler
set to null.
I need to change some code with strong event handlers (i.e. source.PropertyChange += handler;
) to follow the weak pattern. This is trivial using the AddHandler
method. Are there any reasons to prefer AddListener
(which requires me to implement IWeakEventListener
)?
If I were to write new code, what are the reasons to prefer one to the other?
AddHandler
would be easier to create your own leaks with (seeing how you need to keep track of a delegate) – Mercorr