Silverlight 4 TreeView 中的虚假 MouseEnter/MouseLeave 事件

发布于 2024-09-19 01:32:58 字数 1350 浏览 13 评论 0原文

我试图使用 MouseLeave 事件来隐藏包含 TreeView 对象的 Popup 控件。没过多久就偶然发现了第一个细微差别,即 Popup 控件不会发出 MouseLeave 事件。因此,我采用了规定的黑客方法并捕获了 Child 对象的事件。然后我遇到了第二个细微差别。一旦鼠标进入控件,MouseLeave 事件就会触发。我发现,当进入 TreeView 对象时,TreeView 控件会发出一系列交替的 MouseEnter 和 MouseLeave 事件。

下面的代码在 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

在我期望看到的地方

MouseEnter 1
...
MouseLeave 2

,我却看到了

MouseEnter 1
MouseLeave 2
MouseEnter 3
...
MouseLeave 4

因此,隐藏 MouseLeave 上的控件是一场失败的战斗。关于正在发生的事情或可以采取哪些措施来解决这个问题有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文