Prev | Current Page 314 | Next

Matthew MacDonald

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

But the Click event supports
event bubbling, which gives you a better option. You can handle all the button clicks by handling
the Click event at a higher level (such as the containing StackPanel).
Unfortunately, this apparently obvious code doesn??™t work:




...

The problem is that the StackPanel doesn??™t include a Click event, so this is interpreted by
the XAML parser as an error. For the same reason, the Handles statement won??™t work. The
solution is to use a different attached-event syntax in the form ClassName.EventName. Here??™s
the corrected example:




...

Now your event handler receives the click for all contained buttons.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 162
nNote The Click event is actually defined in the ButtonBase class and inherited by the Button class. If you
attach an event handler to ButtonBase.Click, that event handler will be used when any ButtonBase-derived
control is clicked (including the Button, RadioButton, and CheckBox classes).


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