wpf ObjectAnimationUsingKeyFrames设置左值

wpf ObjectAnimationUsingKeyFrames设置左值,wpf,storyboard,Wpf,Storyboard,在WPF中,我尝试将图像从左移到中心,暂停一秒钟,然后将图像移到右。 我正在尝试使用ObjectAnimationUsingKeyFrames来实现它 <BeginStoryboard> <Storyboard Storyboard.TargetName="RoundNumberText" > <ObjectAnimationUsingKeyFrames Duration="0:0:1" Storyboard.TargetProperty="Left"&

在WPF中,我尝试将图像从左移到中心,暂停一秒钟,然后将图像移到右。 我正在尝试使用ObjectAnimationUsingKeyFrames来实现它

<BeginStoryboard>
  <Storyboard Storyboard.TargetName="RoundNumberText" >
    <ObjectAnimationUsingKeyFrames Duration="0:0:1" Storyboard.TargetProperty="Left">
        <DiscreteObjectKeyFrame  Value="400" KeyTime="0:0:0.5"/>
        <DiscreteObjectKeyFrame  Value="1400" KeyTime="0:0:1.5"/>
    </ObjectAnimationUsingKeyFrames>
  </Storyboard>
</BeginStoryboard>

不知怎的,我在TargetProperty上得到了错误消息,该属性不支持该对象。我也试过使用边距,但仍然给出了错误。
如果有人能提供帮助,我们将不胜感激。

要设置对齐的值,您需要执行以下操作:

<ObjectAnimationUsingKeyFrames Storyboard.TargetName="MyImage" 
                               Storyboard.TargetProperty="HorizontalAlignment">

    <DiscreteObjectKeyFrame KeyTime="0:0:0">
        <DiscreteObjectKeyFrame.Value>
            <HorizontalAlignment>Center</HorizontalAlignment>
        </DiscreteObjectKeyFrame.Value>
    </DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>

对于上述编码,我可以包括AccelerationRatio=“.2”或DecelerationRatio=“.8”吗?因为我想把它制作成动画。@user2711132:你为什么不在你的问题中提到
AccelerationRatio
?可能不是,只包含属性
KeyTime
。据我所知,动画对齐仅适用于
DiscreteObjectKeyFrame
,但您可以为
BeginTime
设置不同的值。使用
DoubleAnimation
如何?但是第二个动画会覆盖第一个动画,有没有想在中间暂停它?@ USER 1711132:你尝试过我的代码吗?他这样做,在第二个
对象动画中使用关键帧
,以
开始时间
的形式存在延迟。在这种情况下,不能使用双动画,可以使用我的示例,或者使用。它可以设置
边距的动画
,借助于此,您可以移动图像。对于此动画,您将能够应用
AccelerationRatio
。是AccelerationRatio的一个示例。安纳托利,我通过添加此BeginTime=“0:0:5”来解决计时问题,感谢提供的示例。
<Grid>
    <Grid.Triggers>
        <EventTrigger SourceName="MoveToCenter" RoutedEvent="Button.Click">
            <BeginStoryboard>
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Test" 
                                                   Storyboard.TargetProperty="HorizontalAlignment">

                        <DiscreteObjectKeyFrame KeyTime="0:0:0">
                            <DiscreteObjectKeyFrame.Value>
                                <HorizontalAlignment>Center</HorizontalAlignment>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>

                    <ObjectAnimationUsingKeyFrames BeginTime="0:0:1"
                                                   Storyboard.TargetName="Test" 
                                                   Storyboard.TargetProperty="HorizontalAlignment">

                        <DiscreteObjectKeyFrame KeyTime="0:0:0">
                            <DiscreteObjectKeyFrame.Value>
                                <HorizontalAlignment>Right</HorizontalAlignment>
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>

    <Label x:Name="Test" Content="Test" Width="300" Height="200" Background="Aqua" HorizontalAlignment="Left" />

    <Button Name="MoveToCenter" Content="MoveToCenter" Width="120" Height="30" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
</Grid>