WPF - animate image source change

前端 未结 1 779
梦如初夏
梦如初夏 2021-02-09 13:54

I\'m pretty new to WPF but I think what I need to do is relatively simple. I need to create an image \"animation\", where I am changing an image source every .25 of a second.

相关标签:
1条回答
  • 2021-02-09 14:35

    A pure XAML solution could look like this, of course with different images and timings.

    <Image>
        <Image.Triggers>
            <EventTrigger RoutedEvent="Loaded">
                <BeginStoryboard>
                    <Storyboard RepeatBehavior="Forever">
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Source"
                                                       Duration="0:0:2">
                            <DiscreteObjectKeyFrame KeyTime="0:0:0">
                                <DiscreteObjectKeyFrame.Value>
                                    <BitmapImage UriSource="C:\Users\Public\Pictures\Sample Pictures\Koala.jpg"/>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                            <DiscreteObjectKeyFrame KeyTime="0:0:1">
                                <DiscreteObjectKeyFrame.Value>
                                    <BitmapImage UriSource="C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg"/>
                                </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Image.Triggers>
    </Image>
    
    0 讨论(0)
提交回复
热议问题