【问题标题】:Change an image during animation using storyboard使用情节提要在动画期间更改图像
【发布时间】:2010-12-20 10:49:49
【问题描述】:

我正在寻找一种在情节提要期间更改 图像 的方法,或者更具体地说,更改图像的 Source 属性以指向新的图像资源。似乎有一个 StringAnimationUsingKeyFrames 和一个 DiscreteStringKeyFrame 但这不起作用(据我所知),因为 Image 的 Source 属性的类型是 ImageSource

我当前的故事板是这样的

<Storyboard x:Key="TransitionImage">
    <DoubleAnimationUsingKeyFrames
        BeginTime="00:00:00" 
        Storyboard.TargetName="image" 
        Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
        <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0.2"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.5000000" Value="1"/>
    </DoubleAnimationUsingKeyFrames>
    <StringAnimationUsingKeyFrames
        BeginTime="00:00:00"
        Storyboard.TargetName="image"
        Storyboard.TargetProperty="(Image.Source)">
        <!-- This does not work -->
        <DiscreteStringKeyFrame KeyTime="00:00:00.7000000" Value="check_24.png"/>
    </StringAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames 
        BeginTime="00:00:00" 
        Storyboard.TargetName="image"
        Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
        <SplineDoubleKeyFrame KeyTime="00:00:00.7000000" Value="0.2"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.5000000" Value="1"/>
    </DoubleAnimationUsingKeyFrames>
</Storyboard>

还有图片

<Image x:Name="image" 
       Source="delete_24.png"
       Width="32" Height="32"
       Margin="8"
       RenderTransformOrigin="0.5,0.5">
    <Image.RenderTransform>
        <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
        </TransformGroup>
    </Image.RenderTransform>
</Image>

我可以将图像的Source 更改为情节提要的一部分还是我不走运?

【问题讨论】:

    标签: wpf image xaml storyboard


    【解决方案1】:

    好的,我自己解决了。看来你必须使用ObjectAnimationUsingKeyFramesDiscreteObjectKeyFrame,如下所示:

    <ObjectAnimationUsingKeyFrames 
        BeginTime="00:00:00" 
        Storyboard.TargetName="image"
        Storyboard.TargetProperty="(Image.Source)">
        <DiscreteObjectKeyFrame KeyTime="00:00:00.7000000">
            <DiscreteObjectKeyFrame.Value>
                <BitmapImage UriSource="check_24.png" />
            </DiscreteObjectKeyFrame.Value>
        </DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
    

    【讨论】:

    • 如何将BitmapImage UriSource与动态内容绑定
    猜你喜欢
    • 2017-04-26
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 2012-02-18
    • 1970-01-01
    相关资源
    最近更新 更多