IWeakEventListener.ReceiveWeakEvent Method (Type, Object, EventArgs)
Receives events from the centralized event manager.
Assembly: WindowsBase (in WindowsBase.dll)
Object that originated the event.
Return ValueType: System.Boolean
true if the listener handled the event. It is considered an error by the WeakEventManager handling in WPF to register a listener for an event that the listener does not handle. Regardless, the method should return false if it receives an event that it does not recognize or handle.
Notes to Implementers:
This method is intended to receive all possible events where the receiver is in a listener list. Particularly if implementing for a class that is listening for more than one event, you must check the type of the incoming managerType parameter in order to know which event the call corresponds to. This is why each event that is to be part of the pattern must have a dedicated WeakEventManager. Also, the e parameter is typed as the general EventArgs. Therefore, in order get any specific properties out of the event data, your implementation will need to cast to the specific event data type.
Typically, after checking for the identity of the event based on the WeakEventManager type, your implementation should call a private class handler. Your class handler could conceivably be the very same class handler that is used to handle that event for listeners that are added through the conventional event pattern of adding via += to the event on the sender. The following example section provides a rough implementation template.
The following example implements ClockwiseSpin and CounterclockwiseSpin that each have a dedicated WeakEventManager (not shown). This implementation calls class handler stubs for each supported event, casting the event data (in this case the two events share an event data type SpinEventArgs). The implementation returns false if the event received is not one that is expected.to provide WeakEvent pattern support for two hypothetical events
Available since 3.0