views:

27

answers:

0

I was trying to use the MouseLeave event to hide a Popup control that contained a TreeView object. It didn't take long to stumble upon the first nuance, that the Popup control doesn't emit a MouseLeave event. So I went with the prescribed hackaround and captured the events from the Child object. Then I came across the second nuance. The MouseLeave event was firing as soon as the mouse entered the control. I discovered that the TreeView control was emitting a series of alternating MouseEnter and MouseLeave events when entering the TreeView object.

The following code produces evidence of this with IE8:

Public Class MainApp
    Inherits Application

    Dim _cnt As Integer = 1

    Public Sub New()
        AddHandler Me.Startup, AddressOf HandleStartup
    End Sub

    Private Sub HandleStartup()
        Dim tv As New TreeView
        AddHandler tv.MouseEnter, AddressOf HandleMouseEnter
        AddHandler tv.MouseLeave, AddressOf HandleMouseLeave
        RootVisual = tv
    End Sub
    Private Sub HandleMouseEnter(ByVal sender As Object, ByVal ev As MouseEventArgs)
        System.Diagnostics.Debugger.Log(0, Nothing, "MouseEnter " & _cnt & vbCrLf)
        _cnt += 1
    End Sub
    Private Sub HandleMouseLeave(ByVal sender As Object, ByVal ev As MouseEventArgs)
        System.Diagnostics.Debugger.Log(0, Nothing, "MouseLeave " & _cnt & vbCrLf)
        _cnt += 1
    End Sub

End Class

Where I would expect to see

MouseEnter 1
...
MouseLeave 2

instead I see

MouseEnter 1
MouseLeave 2
MouseEnter 3
...
MouseLeave 4

So hiding the control on MouseLeave is a losing battle. Any ideas on what is going on or what can be done to work around it?