难以使 DoubleAnimationUsingKeyFrames 工作
Difficulty in getting DoubleAnimationUsingKeyFrames to work
我正在尝试将此故事板 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()
您似乎在两个动画上绑定了不正确的 属性 路径。你要
New PropertyPath("Projection.RotationY")
或者也许
New PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)")
因为 front
和 back
不直接包含 PlaneProjection.RotationYProperty
.
我正在尝试将此故事板 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()
您似乎在两个动画上绑定了不正确的 属性 路径。你要
New PropertyPath("Projection.RotationY")
或者也许
New PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)")
因为 front
和 back
不直接包含 PlaneProjection.RotationYProperty
.