难以让DoubleAnimationUsingKeyFrames工作

时间:2015-01-15 17:37:01

标签: vb.net xaml windows-phone-8 windows-phone-8.1

我试图将此故事板xaml标记转换为vb代码。但是,当我运行代码时,没有任何事情发生,没有异常引发或错误只是没有。有什么东西我不见了吗?

当从xaml运行时,故事板按预期工作,但在我的代码隐藏翻译期间出现了问题。

最后,我可以验证附加到故事板的目标元素是否确实存在。

XMAL

 <Storyboard x:Name="FlipAnimation">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="Front">
            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="90"/>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Projection).(PlaneProjection.RotationY)" Storyboard.TargetName="Back">
            <EasingDoubleKeyFrame KeyTime="0" Value="-90"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="-90"/>
            <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

代码背后

 Dim firstKf As DoubleAnimationUsingKeyFrames = New DoubleAnimationUsingKeyFrames
    firstKf.KeyFrames.Add(New EasingDoubleKeyFrame With {.KeyTime = TimeSpan.Zero, .Value = "0"})
    firstKf.KeyFrames.Add(New EasingDoubleKeyFrame With {.KeyTime = TimeSpan.FromMilliseconds(200), .Value = "90"})
    Media.Animation.Storyboard.SetTargetProperty(firstKf, New PropertyPath(PlaneProjection.RotationYProperty))
    Media.Animation.Storyboard.SetTarget(firstKf, front)

    Dim secondKf As DoubleAnimationUsingKeyFrames = New DoubleAnimationUsingKeyFrames
    secondKf.KeyFrames.Add(New EasingDoubleKeyFrame With {.KeyTime = TimeSpan.Zero, .Value = "-90"})
    secondKf.KeyFrames.Add(New EasingDoubleKeyFrame With {.KeyTime = TimeSpan.FromMilliseconds(200), .Value = "-90"})
    secondKf.KeyFrames.Add(New EasingDoubleKeyFrame With {.KeyTime = TimeSpan.FromMilliseconds(400), .Value = "0"})
    Media.Animation.Storyboard.SetTargetProperty(secondKf, New PropertyPath(PlaneProjection.RotationYProperty))
    Media.Animation.Storyboard.SetTarget(secondKf, back)

    Dim sb = New Media.Animation.Storyboard
    sb.Children.Add(firstKf)
    sb.Children.Add(secondKf)
    sb.Begin()

1 个答案:

答案 0 :(得分:0)

看起来你绑定了两个动画上的错误属性路径。你想要

New PropertyPath("Projection.RotationY")

或者

New PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)")

由于frontback不直接包含PlaneProjection.RotationYProperty