Mediates an EventHandler event, holding only a weak reference to the event sink. Thus there is no reference created from the event source to the event sink, and the event sink can be garbage collected.
Typical use: (Attention: source has to be a local variable, not a member variable!)
source.Changed += new WeakEventHandler(this.EhHandleChange, x => source.Changed -= x);Sometimes it might be neccessary to use explicitly the event handler method of this instance:
source.Changed += new WeakEventHandler(this.EhHandleChange, x=> source.Changed -= x.EventSink).EventSink;You can even maintain a reference to the WeakActionHandler instance in your event sink instance, in case you have to remove the event handling programmatically:
_weakEventHandler = new WeakEventHandler(this.EhHandleChange, x => source.Changed -= x); // weakEventHandler is an instance variable of this class source.Changed += _weakEventHandler; . . . source.Changed -= _weakEventHandler;
Constructor | Description |
Full Usage:
WeakPropertyChangedEventHandler(handler, eventSource, eventName)
Parameters:
PropertyChangedEventHandler
-
The event handler method (the event sink).
eventSource : obj
-
The object that holds the event source.
eventName : string
-
The name of the event.
|
Typcical usage: source.Changed += new WeakEventHandler<MyEventArgs>(this.EhHandleChange, source, nameof(source.Changed));
|
Full Usage:
WeakPropertyChangedEventHandler(handler, eventSourceType, eventName)
Parameters:
PropertyChangedEventHandler
-
The event handler method (the event sink).
eventSourceType : Type
-
The type of object that holds the static event.
eventName : string
-
The name of the static event.
|
Typical usage: StaticClass.Changed += new WeakActionHandler(this.EhHandleChange, typeof(StaticClass), nameof(StaticClass.Changed));
|
Instance member | Description |
Full Usage:
this.EventSink
Parameters:
obj
-
Sender of the event.
e : EventArgs
-
Event args.
|
Handles the event from the original source. You must not call this method directly. However, it can be neccessary to use the method reference if the implicit casting fails. See remarks in the description of this class.
|
Full Usage:
this.EventSource
Returns: obj
|
Gets the event source. Attention! Use the returned value only locally, otherwise, you will get a dependence that you wanted to avoid.
|
Full Usage:
this.Remove
|
Removes the event handler from the event source, using the stored remove action.. |
Static member | Description |
Full Usage:
op_ImplicitweakHandler
Parameters:
WeakPropertyChangedEventHandler
Returns: PropertyChangedEventHandler
|
|