IWeakEventListener::ReceiveWeakEvent Method (Type^, Object^, EventArgs^)


Receives events from the centralized event manager.

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

bool ReceiveWeakEvent(
	Type^ managerType,
	Object^ sender,
	EventArgs^ e


Type: System::Type^

The type of the WeakEventManager calling this method.

Type: System::Object^

Object that originated the event.

Type: System::EventArgs^

Event data.

Return Value

Type: 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 ReceiveWeakEvent to provide WeakEvent pattern support for two hypothetical events 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.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.0
Return to top