jpg" Stretch="None" />
Courtesy of the StackPanelAs you already know, every ingredient you place in a WPF window derives from
UIElement at some point, including the Label, StackPanel, TextBlock, and Image. UIElement
defines some core events. For example, every class that derives from UIElement provides a
MouseDown and MouseUp event.
But consider what happens when you click the image part of the fancy label shown here.
Clearly, it makes sense for the Image.MouseDown and Image.MouseUp events to fire. But
what if you want to treat all label clicks in the same way? In this case, it shouldn??™t matter
whether the user clicks the image, some of the text, or part of the blank space inside the label
border. In every case, you??™d like to respond with the same code.
Clearly, you could wire up the same event handler to the MouseDown or MouseUp event
of each element, but that would result in a significant amount of clutter and it would make
your markup more difficult to maintain. WPF provides a better solution with its routed event
model.
Routed events actually come in the following three flavors:
??? Direct events are like ordinary .NET events. They originate in one element and don??™t
pass to any other. For example, MouseEnter (which fires when the mouse pointer
moves over an element) is a direct event.
Pages:
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317