3

在 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 上收到了该属性不支持该对象的错误消息。我也尝试过保证金,但仍然给出错误。感谢是否有人可以提供帮助。

4

1 回答 1

3

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

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

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

下面是我的示例,其中图像出现在角色中Label

<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>
于 2013-08-24T10:23:00.583 回答