0

我的代码发布在下面。我正在创建一个图像,并尝试向它添加动画。我确信它在某个时候有效,我做了一个小改动,它失败了我撤消了更改(字面意思是撤消),现在它继续失败。我正在尝试将图像每半秒更改为另一个图像,然后再过半秒再变回来。

<Image Height="30" HorizontalAlignment="Left" Margin="198,90,0,0" Name="OldMan" Stretch="Fill" VerticalAlignment="Top" Width="30" Source="/TestingWpF;component/Images/Old1.png" >
    <Image.Triggers>
        <EventTrigger RoutedEvent="Window.Loaded">
            <BeginStoryboard>
                <Storyboard >
                    <ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="OldMan" Storyboard.TargetProperty="(Image.Source)" RepeatBehavior="Forever">
                        <DiscreteObjectKeyFrame KeyTime="00:00:00.5000000">
                            <DiscreteObjectKeyFrame.Value>
                                <BitmapImage UriSource="/TestingWpF;component/Images/Old1.png" />
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                        <DiscreteObjectKeyFrame KeyTime="00:00:01.0000000">
                            <DiscreteObjectKeyFrame.Value>
                                <BitmapImage UriSource="/TestingWpF;component/Images/Old2.png" />
                            </DiscreteObjectKeyFrame.Value>
                        </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Image.Triggers>
</Image>
4

1 回答 1

1

问题是您没有设置持续时间。你只会得到第一个关键帧,而不是下一个。Duration="00:00:01.5"尝试添加类似ObjectAnimationUsingKeyFrames

于 2012-05-17T14:44:06.903 回答