将缓动函数应用于Windows Phone中的DiscreteObjectKeyFrame动画

时间:2012-05-18 18:21:40

标签: silverlight windows-phone-7 xaml animation storyboard

<Storyboard x:Name="stTOPAni">
        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="grdOverlay">
            <DiscreteObjectKeyFrame KeyTime="0">
                <DiscreteObjectKeyFrame.Value>
                    <Thickness>0</Thickness>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
            <DiscreteObjectKeyFrame x:Name="key1" KeyTime="0:0:0.5">
                <DiscreteObjectKeyFrame.Value>
                    <Thickness>0,-500,0,0</Thickness>
                </DiscreteObjectKeyFrame.Value>

            </DiscreteObjectKeyFrame>
            <DiscreteObjectKeyFrame KeyTime="0:0:1">
                <DiscreteObjectKeyFrame.Value>
                    <Thickness>0,-800,0,0</Thickness>
                </DiscreteObjectKeyFrame.Value>
            </DiscreteObjectKeyFrame>
        </ObjectAnimationUsingKeyFrames>

    </Storyboard>

我想使用这个故事板更改上边距,所以我应用KeyFrame动画,但它不使用EasingFunction因此不顺畅,我将如何应用Easing Function来使动画流畅!

1 个答案:

答案 0 :(得分:0)

在WPF中,你可以简单地使用其中一个...... ThicknessKeyFrames。

<Storyboard x:Name="stTOPAni" Storyboard.TargetProperty="Margin">
    <ThicknessAnimationUsingKeyFrames>
        <DiscreteThicknessKeyFrame KeyTime="0">
            <DiscreteThicknessKeyFrame.Value>
                <Thickness>0</Thickness>
            </DiscreteThicknessKeyFrame.Value>
        </DiscreteThicknessKeyFrame>
        <EasingThicknessKeyFrame KeyTime="0:0:1">
            <EasingThicknessKeyFrame.EasingFunction>
                <CubicEase EasingMode="EaseInOut"/>
            </EasingThicknessKeyFrame.EasingFunction>
            <EasingThicknessKeyFrame.Value>
                <Thickness>0,-800,0,0</Thickness>
            </EasingThicknessKeyFrame.Value>
        </EasingThicknessKeyFrame>
    </ThicknessAnimationUsingKeyFrames>
</Storyboard>

但不幸的是,在Silverlight中,动画不能流畅,因为你必须使用ObjectAnimationUsingKeyFrames Thickness动画only supports discrete interpolation methodEasingFunctions也不受支持。