WeakEventManager.ProtectedAddListener Method (Object, IWeakEventListener)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Adds the provided listener to the provided source for the event being managed.

Namespace:   System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

protected void ProtectedAddListener(
	object source,
	IWeakEventListener listener


Type: System.Object

The source to attach listeners to.

Type: System.Windows.IWeakEventListener

The listening class (which must implement IWeakEventListener).

Call this method within your manager class AddListener methods on WeakEventManager implementations. AddListener is the suggested name for the static method you define on your manager class to enable other classes to add a listener for your weak event pattern. AddListener should take two parameters: the source where the listener is attached, and the listener instance. For your AddListener implementation, call the ProtectedAddListener method on the current manager and pass the same two parameters.

If the list of listeners was previously empty, ProtectedAddListener calls the StartListening method internally, which will call your specific StartListening override through polymorphism.

ProtectedAddListener adds listeners to a single internal WeakEventManager.ListenerList per source. If your manager implementation maintains more than one list of listeners for each event-source combination, do not use ProtectedAddListener. Instead, your implementation should create its own WeakEventManager.ListenerList instances, AddListener should add listeners to the appropriate list, and events should be delivered to the appropriate listener list by calling the DeliverEventToList event instead of the DeliverEvent method.

.NET Framework
Available since 3.0
Return to top