Book Image

Mastering Windows Presentation Foundation

By : Sheridan Yuen
Book Image

Mastering Windows Presentation Foundation

By: Sheridan Yuen

Overview of this book

Windows Presentation Foundation is rich in possibilities when it comes to delivering an excellent user experience. This book will show you how to build professional-grade applications that look great and work smoothly. We start by providing you with a foundation of knowledge to improve your workflow – this includes teaching you how to build the base layer of the application, which will support all that comes after it. We’ll also cover the useful details of data binding. Next, we cover the user interface and show you how to get the most out of the built-in and custom WPF controls. The final section of the book demonstrates ways to polish your applications, from adding practical animations and data validation to improving application performance. The book ends with a tutorial on how to deploy your applications and outlines potential ways to apply your new-found knowledge so you can put it to use right away.
Table of Contents (19 chapters)
Mastering Windows Presentation Foundation
About the Author
About the Reviewer
Customer Feedback

Handling events

One of the most common causes of memory leaks appearing in an application is the failure to remove event handlers once objects are no longer needed. When we attach an event handler to an object's event in the usual way, we are effectively passing that object a reference to the handler and creating a hard reference to it.

When the object is no longer needed and could otherwise be disposed of, the reference in the object that raises the event will prevent that from occurring. This is because the garbage collector cannot collect an object that can be accessed from any part of the application code. In the worst case scenario, the object being kept alive may contain numerous other objects and so inadvertently keep them alive also.

The problem with this is that keeping objects alive after they are no longer needed will unnecessarily increase the memory footprint of the application, in some cases, with dramatic and irreversible consequences, leading to an OutOfMemoryException being...