Chapter 4. Input
A user interface wouldn't be much use if it couldn't respond to user
input. In this chapter, we will examine the input handling mechanisms
available in WPF. There are three main kinds of user input for a Windows
application: mouse, keyboard, and ink.[19] Any user interface element can receive input—not just
controls. This is not surprising, because controls rely entirely on the
services of lower-level elements like Rectangle and TextBlock in order to provide visuals. All of
the input mechanisms described in the following sections are, therefore,
available on all user interface element types.
Raw user input is delivered to your code through WPF's routed event mechanism. There is also a higher-level concept of a command—a particular action that might be accessible through several different inputs such as keyboard shortcuts, toolbar buttons, and menu items.
Routed Events
The .NET Framework defines a standard mechanism for managing events. A class may expose several events, and each event may have any number of subscribers. WPF augments this standard mechanism to overcome a limitation: if a normal .NET event has no registered handlers, it is effectively ignored.
Consider what this would mean for a typical WPF control. Most
controls are made up of multiple visual components. For example, suppose
you give a button a very plain appearance consisting of a single
Rectangle, and provide a simple piece
of text as the content. (Chapter 9 describes how to customize a control's appearance.) ...