I’m trying to make an image fade in/out when the user hovers over the button. The fadein works when I enter the button but not when I leave it. How can I make this work?
Animation Code:
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
Button code:
Private Sub btn_2_MouseEnter(sender As Object, e As System.Windows.Input.MouseEventArgs) Handles btn_2.MouseEnter
GreenBg_animation()
End Sub
You need another (reverse) animation on
MouseExit, if you thought thatAutoReversewould do that for you you are mistaken.