【问题标题】:XAML - How do I create a DoubleAnimationUsingKeyFrames dynamically and play the storyboard with VB?XAML - 如何动态创建 DoubleAnimationUsingKeyFrames 并使用 VB 播放情节提要?
【发布时间】:2012-09-08 00:29:58
【问题描述】:

我有 3 个多边形,我试图根据动态代码“点亮”(改变不透明度)。例如,我有一长串随机数(021200112)。我正在尝试使用关键帧创建动态故事板。我正在使用单个多边形对其进行测试,但出现了目标错误。感谢您的帮助!!!

多边形是在 XAML 中创建的(命名为 Poly1、Poly2、Poly3)。

这是我尝试播放情节提要时的错误:

WinRT information: Cannot resolve TargetProperty 1 on specified object.

这是我在 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

【问题讨论】:

    标签: xaml animation storyboard microsoft-metro


    【解决方案1】:

    目标属性是要设置动画的属性的名称(或者,更具体地说,PropertyPath,但可以从字符串转换)。

    尝试以下方法:

    Storyboard.SetTargetProperty(myDoubleAnimationUsingKeyFrames, "Opacity")
    

    【讨论】:

      猜你喜欢
      • 2015-07-17
      • 1970-01-01
      • 2020-11-30
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 2012-10-25
      相关资源
      最近更新 更多