XAML - How do I create a DoubleAnimationUsingKeyFr

2019-09-06 11:06发布

I have 3 polygons that I am trying to "light up" (changing opacity) based on dynamically code. For instance, I have a long string of random numbers (021200112). I'm trying to create a dynamic storyboard with keyframes. I'm testing it with a single polygon and I am getting a target error. Your help is appreciated!!!

The polygons are created in the XAML (named Poly1, Poly2, Poly3).

Here is my error when it tries to play the storyboard:

WinRT information: Cannot resolve TargetProperty 1 on specified object.

Here is my code to test the animation on poly1.

Public Sub PlayStoryboard()

    Dim myDoubleAnimationUsingKeyFrames As New DoubleAnimationUsingKeyFrames()
    Dim myLinearDoubleKeyFrame As New LinearDoubleKeyFrame()
    Dim myLinearDoubleKeyFrame2 As New LinearDoubleKeyFrame()

    myLinearDoubleKeyFrame.Value = 0.2
    myLinearDoubleKeyFrame.KeyTime = TimeSpan.FromSeconds(1)

    myLinearDoubleKeyFrame2.Value = 1
    myLinearDoubleKeyFrame2.KeyTime = TimeSpan.FromSeconds(3)
    myDoubleAnimationUsingKeyFrames.KeyFrames.Add(myLinearDoubleKeyFrame)
    myDoubleAnimationUsingKeyFrames.KeyFrames.Add(myLinearDoubleKeyFrame2)

    myDoubleAnimationUsingKeyFrames.Duration = New Duration(TimeSpan.FromMilliseconds(5000))

    Dim myStoryboard = New Storyboard()
    myStoryboard.Children.Add(myDoubleAnimationUsingKeyFrames)

    Storyboard.SetTarget(myDoubleAnimationUsingKeyFrames, Poly1)
    Storyboard.SetTargetName(myDoubleAnimationUsingKeyFrames, Poly1.Name)
    Storyboard.SetTargetProperty(myDoubleAnimationUsingKeyFrames, Opacity)

    myStoryboard.Begin()

End Sub

1条回答
叛逆
2楼-- · 2019-09-06 12:08

The target property is meant to be the name of the property to animate (or, more specifically, a PropertyPath, but that can be converted from a String).

Try the following:

Storyboard.SetTargetProperty(myDoubleAnimationUsingKeyFrames, "Opacity")
查看更多
登录 后发表回答