Prev | Current Page 311 | Next

Matthew MacDonald

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

MouseUp, Label1.MouseUp, Image1.MouseUp ...
The SomethingClicked() method simply examines the properties of the RoutedEventArgs
object and adds a message to the list box:
Protected eventCounter As Integer = 0
Private Sub SomethingClicked(ByVal sender As Object, _
ByVal e As RoutedEventArgs)
eventCounter += 1
Dim message As String = "#" & eventCounter.ToString() & ":" & _
Constants.vbCrLf & " Sender: " & sender.ToString() & _
Constants.vbCrLf & " Source: " & e.Source.ToString() & _
Constants.vbCrLf & " Original Source: " & _
e.OriginalSource.ToString()
lstMessages.Items.Add(message)
e.Handled = CBool(chkHandle.IsChecked)
End Sub
nNote Technically, the MouseUp event provides a MouseButtonEventArgs object with additional information
about the mouse state at the time of the event. However, the MouseButtonEventArgs object derives from
MouseEventArgs, which in turn derives from RoutedEventArgs. As a result, it??™s possible to use it when
declaring the event handler (as shown here) if you don??™t need additional information about the mouse.
There??™s one other detail in this example. If you??™ve checked the chkHandle check box, the
SomethingClicked() method sets the RoutedEventArgs.Handled property to True, which stops
the event bubbling sequence the first time an event occurs. As a result, you??™ll only see the first
event appear in the list, as shown in Figure 6-2.


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