图像淡入鼠标输入事件

时间:2011-11-19 14:55:24

标签: .net wpf vb.net animation

当用户将鼠标悬停在按钮上时,我正在尝试使图像淡入/淡出。当我进入按钮时,fadein工作,但是当我离开时,fadein不工作。我怎样才能做到这一点?

动画代码:

Private Sub GreenBg_animation()
        Dim myduration As Duration = New Duration(TimeSpan.FromMilliseconds(250))
        Dim da As DoubleAnimation = New DoubleAnimation
        da.Duration = myduration

        Dim sb As Storyboard = New Storyboard
        sb.Duration = myduration
        sb.Children.Add(da)
        Storyboard.SetTarget(da, btn_bg_green)
        Storyboard.SetTargetProperty(da, New PropertyPath(OpacityProperty))
        da.From = 0.0
        da.To = 1.0
        da.AutoReverse = True
        sb.Begin()
    End Sub

按键代码:

 Private Sub btn_2_MouseEnter(sender As Object, e As System.Windows.Input.MouseEventArgs) Handles btn_2.MouseEnter
            GreenBg_animation()
        End Sub

1 个答案:

答案 0 :(得分:0)

你需要MouseExit上的另一个(反向)动画,如果你认为AutoReverse会为你做那件事你就错了。