Image 使用故事板更改图像的源

Image 使用故事板更改图像的源,image,xaml,animation,storyboard,Image,Xaml,Animation,Storyboard,如何使用故事板更改图像源?我想创建一个小动画,为此我想更改一个持续时间为0.5秒的图像源,使其看起来像一个小动画。(有点像Gif动画:))有没有办法用Xaml中的故事板来实现这一点,或者是用定时器从代码后面更改图像源的唯一方法?标准动画只能在引擎可以设置动画的属性上工作。图像的源不是这样的属性,至少不是现成的 您可以使用ObjectAnimationUsingKeyFrames在不同的关键帧准备多个图像并使用情节提要多次设置源属性: <Storyboard x:Key="Storyboar

如何使用故事板更改图像源?我想创建一个小动画,为此我想更改一个持续时间为0.5秒的图像源,使其看起来像一个小动画。(有点像Gif动画:))有没有办法用Xaml中的故事板来实现这一点,或者是用定时器从代码后面更改图像源的唯一方法?

标准动画只能在引擎可以设置动画的属性上工作。图像的源不是这样的属性,至少不是现成的

您可以使用ObjectAnimationUsingKeyFrames在不同的关键帧准备多个图像并使用情节提要多次设置源属性:

<Storyboard x:Key="Storyboard">
    <ObjectAnimationUsingKeyFrames 
        Storyboard.TargetProperty="(Image.Source)" 
        Storyboard.TargetName="Image1">

        <DiscreteObjectKeyFrame KeyTime="0:0:1">
            <DiscreteObjectKeyFrame.Value>
                <BitmapImage UriSource="Images/1.jpeg" />
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:2">
            <DiscreteObjectKeyFrame.Value>
                <BitmapImage UriSource="Images/2.jpeg" />
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>

    </ObjectAnimationUsingKeyFrames>
</Storyboard>

标准动画只能在引擎可以设置动画的属性上工作。图像的源不是这样的属性,至少不是现成的

您可以使用ObjectAnimationUsingKeyFrames在不同的关键帧准备多个图像并使用情节提要多次设置源属性:

<Storyboard x:Key="Storyboard">
    <ObjectAnimationUsingKeyFrames 
        Storyboard.TargetProperty="(Image.Source)" 
        Storyboard.TargetName="Image1">

        <DiscreteObjectKeyFrame KeyTime="0:0:1">
            <DiscreteObjectKeyFrame.Value>
                <BitmapImage UriSource="Images/1.jpeg" />
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:2">
            <DiscreteObjectKeyFrame.Value>
                <BitmapImage UriSource="Images/2.jpeg" />
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>

    </ObjectAnimationUsingKeyFrames>
</Storyboard>