The page has been moved to GitHub

WeakEvent

Package: MyToolkit
Platforms: All (PCL)

When adding an event this way the object can be destroyed even the event handler is still registered. You should ONLY use this class if there is no way to know when to deregister an event (e.g. in the Unloaded event of a page) because it may still have some performance impact.

var handler = WeakEvent.RegisterEvent<
	INotifyPropertyChanged, 
	PropertyChangedEventHandler, 
	PropertyChangedEventArgs>(
		h => (o, e) => h(o3, e),
		h => item.PropertyChanged += h,
		h => item.PropertyChanged -= h,
		this, OnPropertyChanged);

Generic parameters
  1. Type of the sender/object with the event
  2. Type of the event handler
  3. Type of the event arguments (the first method parameter is not needed for generic args e.g. if event is of type EventHandler<TArgs>)

Last edited Jun 3, 2015 at 11:01 PM by rsuter, version 10