Prev | Current Page 335 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

You can also get
the state of the keyboard at any time. The trick is to use the Keyboard class, which is very similar
to KeyboardDevice except it??™s made up of shared members. Here??™s an example that uses the
Keyboard class to check the current state of the left Shift key:
If Keyboard.IsKeyDown(Key.LeftShift) Then
lblInfo.Text = "The left Shift is held down."
End If
nNote The Keyboard class also has methods that allow you to attach application-wide keyboard event
handlers, such as AddKeyDownHandler() and AddKeyUpHandler(). However, these methods aren??™t recommended.
A better approach to implementing application-wide functionality is to use the WPF command
system, as described in Chapter 10.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 175
Mouse Input
Mouse events perform several related tasks. The most fundamental mouse events allow you to
react when the mouse is moved over an element. These events are MouseEnter (which fires
when the mouse pointer moves over the element) and MouseLeave (which fires when the
mouse pointer moves away). Both are direct events, which means they don??™t use tunneling or
bubbling. Instead, they originate in one element and are raised by just that element. This
makes sense because of the way controls are nested in a WPF window.
For example, if you have a StackPanel that contains a button and you move the mouse
pointer over the button, the MouseEnter event will fire first for the StackPanel (once you enter
its borders) and then for the button (once you move directly over it).


Pages:
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347