However, the Handles statement is somewhat
limited. As you??™ll discover in Chapter 6, WPF uses a routed event model that allows you to
handle events at different places in your markup. For example, instead of handling a Click
event on the Button control where it occurs, you can handle it after it bubbles up through your
layout to a containing element. Similarly, you can preview events (such as key presses) in a
CHAPTER 2 n XAML 45
containing element before they??™re received by the control that actually has focus. Both of these
techniques are useful in a variety of situations. However, in many scenarios they work with the
Handles statement.
It??™s up to you whether you want to use a mix of approaches, with the Handles statement
for straightforward event hookup and the event attributes for more complicated examples
that won??™t work with Handles. In this book, all the code examples use event attributes for
consistency.
The Full Eight Ball Example
Now that you??™ve considered the fundamentals of XAML, you know enough to walk through the
definition for the window in Figure 2-1. Here??™s the complete XAML markup:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Eight Ball Answer" Height="328" Width="412" >
Pages:
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152