我想使用ObjectAnimationUsingKeyFrames为winrt中的控件之一设置动画。在一段时间内,控件应从Margin =“ 0,0,-500,0”移至Margin =“ 0,0,0,0”。我有以下代码。几乎可以使用,但是所有操作都立即发生,并且看不到动画或平滑过渡。
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="NameOfControl"
Storyboard.TargetProperty="(FrameworkElement.Margin)"
Duration="00:00:00.5">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Thickness>0,0,-500,0</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="00:00:0.5">
<DiscreteObjectKeyFrame.Value>
<Thickness>0,0,0,0</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
我想,我找到了。看这段代码。(它将控件向下移动100点,向右移动100点)
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="TextBlock1" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="100"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="TextBlock1" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)">
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
<EasingDoubleKeyFrame KeyTime="0:0:1" Value="100"/>
</DoubleAnimationUsingKeyFrames>
但是您不能忘记添加此代码来控制您要移动的代码。
<TextBlock Name="TextBlock1" Text="SomeText">
<TextBlock.RenderTransform>
<CompositeTransform/>
</TextBlock.RenderTransform>
</TextBlock>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句