O'Reilly logo

Pro WPF and Silverlight MVVM: Effective Application Development with Model-View-ViewModel by Gary McLean Hall

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 5. Events and Commands

Events

An event is a programming construct that reacts to a change in state, notifying any endpoints that have registered for notification. They are ubiquitous in .NET generally, and this continues in WPF and Silverlight. Primarily, events are used to inform of user input via the mouse and keyboard, but their utility is not limited to that. Whenever a state change is detected, perhaps when an object has been loaded or initialized, an event can be fired to alert any interested third parties.

Events in .NET

In .NET, events are first-class citizens: they are represented by delegates and declared with the event keyword (see Listing 5-1).

Example 5.1. Declaring a Plain Event in .NET

delegate void MyEventHandler(); ... public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required