Question : WPF Storyboard

I am new to WPF and the storyboard is really doing my head in.

I have a control that I fade in using a story board. This works fine, but after it has run I am unable to set the Opacity on the control by code.

The question is why and how do I fix it, I think it needs to be released but I can't find any information on it.

Here is my code, after the control is loaded I manually call the FadeIn event.

Also I have checked the Image_MouseEnter event IS being fired!
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
Imports System.Windows.Media.Animation

Public Class UserControl1

    Private storyboard As New Storyboard()

    Private duration As New TimeSpan(0, 0, 2)

    Private animation As New DoubleAnimation()

    Private Sub Image1_MouseEnter(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles Image1.MouseEnter

        Try

            Me.Image1.Opacity = 1.0

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

    End Sub

    Public Sub FadeIn()

        storyboard.AutoReverse = False

        animation.From = 0.0

        animation.To = 0.5

        animation.Duration = New Duration(Duration)


        Storyboard.SetTargetName(animation, Me.Image1.Name)

        Storyboard.SetTargetProperty(animation, New PropertyPath(UIElement.OpacityProperty))

        Storyboard.Children.Add(animation)

        storyboard.Begin(Me.Image1)

    End Sub

End Class

Answer : WPF Storyboard

Random Solutions  
 
programming4us programming4us