-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Microsoft .NET Framework 4.5 Quickstart Cookbook
By :
Normal event handlers are defined using the += operator and the source keeps a reference to its listeners. If this reference is not removed, it prevents the listener from receiving garbage data. This is one of the most common causes of memory leaks, which are now much easier to avoid.
WPF 4.5 WeakEventManager provides us with a central event dispatching capability that allows the listeners to be de-allocated from memory, while the event is still alive.
While this is not a strictly new behavior, WPF 4.5 brings us enhanced support to set up a weak reference to an event. Prior to this version of WPF, we had to create a weak event manager for every event. This is not the case anymore. Now we can use a generic WeakEventManager for this; let's see how it works.
In order to use this recipe you should have Visual Studio 2012 installed.
Here we will implement some events with the WeakEventManager class.
First, open Visual Studio...
Change the font size
Change margin width
Change background colour