Prev | Current Page 316 | Next

Matthew MacDonald

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

">Command 1


...

You can then access the Tag property in your code:
Private Sub DoSomething(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim tag As Object = CType(sender,FrameworkElement).Tag
MessageBox.Show(CType(tag,String))
End Sub
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 163
Tunneling Events
Tunneling events work the same as bubbling events, but in the opposite direction. For example,
if MouseUp was a tunneled event (which it isn??™t), clicking the image in the fancy label
example would cause MouseUp to fire first in the window, then in the Grid, then in the
StackPanel, and so on until it reaches the actual source, which is the image in the label.
Tunneling events are easy to recognize because they begin with the work Preview. Furthermore,
WPF usually defines bubbling and tunneling events in pairs. That means if you find
a bubbling MouseUp event, you can probably also find a tunneling PreviewMouseUp event.
The tunneling event always fires before the bubbling event, as shown in Figure 6-3.
Figure 6-3. Tunneling and bubbling events
To make life more interesting, if you mark the tunneling event as handled the bubbling event
won??™t occur.


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