Because the size of a screen pixel no longer matches the size of the WPF unit
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 176
system, the physical mouse position may be translated to a fractional number of WPF units, as
shown here.
nTip The UIElement class also includes two useful properties that can help with mouse hit-testing. Use
IsMouseOver to determine whether a mouse is currently over an element or one of its children, and use
IsMouseDirectlyOver to find out whether the mouse is over an element but not one of its children. Usually,
you won??™t read and act on these values in code. Instead, you??™ll use them to build style triggers that automatically
change elements as the mouse moves over them. Chapter 12 demonstrates this technique.
Mouse Clicks
Mouse clicks unfold in a similar way to key presses. The difference is that there are distinct
events for the left mouse button and the right mouse button. Table 6-7 lists these events in the
order they occur. Along with these are two events that react to the mouse wheel: Preview-
MouseWheel and MouseWheel.
Table 6-7.Mouse Click Events for All Elements (in Order)
Name Routing Type Description
PreviewMouseLeftButtonDown Tunneling Occurs when a mouse button is
and PreviewMouseRightButtonDown pressed
MouseLeftButtonDown Bubbling Occurs when a mouse button is
pressed
PreviewMouseLeftButtonUp Tunneling Occurs when a mouse button is
and PreviewMouseRightButtonUp released
MouseLeftButtonUp and Bubbling Occurs when a mouse button is
MouseRightButtonUp released
All mouse button events provide a MouseButtonEventArgs object.
Pages:
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349