Prev | Current Page 312 | Next

Matthew MacDonald

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


CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 160
nNote There??™s an extra cast required here because the CheckBox.IsChecked property is a nullable Boolean
value (a Nullable(Of Boolean) rather than a Boolean). The null value (Nothing) represents an indeterminate
state for the check box, which means it??™s neither checked nor unchecked. This feature isn??™t used in this
example, so a simple cast solves the problem.
Figure 6-2.Marking an event as handled
Because the SomethingClicked() method handles the MouseUp event that??™s fired by the
Window, you??™ll be able to intercept clicks on the list box and the blank window surface. However,
the MouseUp event doesn??™t fire when you click the Clear button (which removes all the
list box entries). That??™s because the button includes an interesting bit of code that suppresses
the MouseUp event and raises a higher-level Click event. At the same time, the Handled flag is
set to True, which prevents the MouseUp event from going any further.
nTip Unlike Windows Forms controls, most WPF elements don??™t expose a Click event. Instead they include
the more straightforward MouseDown and MouseUp events. Click is reserved for button-based controls.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 161
Handling a Suppressed Event
Interestingly, there is a way to receive events that are marked as handled.


Pages:
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324