The WeakEventListener allows the owner to be garbage collected if its only remaining link is an event handler.


Property Type Description
OnDetachAction WeakEventListener<TInstance,TSource,TEventArgs>> Gets or sets the method to call when detaching from the event
OnEventAction Action<TInstance,TSource,TEventArgs> Gets or sets the method to call when the event fires


Methods Return Type Description
Detach() void Detaches from the subscribed event
OnEvent(TSource, TEventArgs) void Handler for the subscribed event calls OnEventAction to handle it

Sample Code

You can find examples of WeakEventListener in our unit tests


Device family Universal, 10.0.16299.0 or higher
Namespace Microsoft.Toolkit.Uwp
NuGet package Microsoft.Toolkit.Uwp

API Source Code