C# XAML Metro Image 动态源 [英] C# XAML Metro Image dynamic Source

查看:25
本文介绍了C# XAML Metro Image 动态源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢使用 XAML 中的一个 Image 控件制作简单的动画,并以 1 秒为间隔将 Image 的源切换到另一个.

I like to do simple animation using one Image control in XAML and swaping Source of Image to other in interval 1 second.

但是当我这样做时,图像闪烁.我使用此代码(在 TimerTick 事件处理程序中):

But when I do that, the image is flickering. I using this code (at Tick event handler of Timer):

Uri uri = new Uri("ms-appx:/Sprites/Running/" + y++ + ".png", 
              UriKind.RelativeOrAbsolute);
BitmapImage textureBitmap = new BitmapImage(uri);

this.ImageHolder.Source = textureBitmap;

问题出在哪里?我应该缓存 BitmapImages 吗?

Where can the problem be ? Should I cache BitmapImages?

感谢您的帮助.

推荐答案

尝试声明一个 StoryBoard:

    <Storyboard>
        <ObjectAnimationUsingKeyFrames BeginTime="0:0:0" 
            Storyboard.TargetName="ImageHolder" Storyboard.TargetProperty="Source">
            <DiscreteObjectKeyFrame KeyTime="0:0:0" 
               Value="{Binding Source={StaticResource Frame1Image}"/>
            <DiscreteObjectKeyFrame KeyTime="0:0:1" 
               Value="{Binding Source={StaticResource Frame2Image}"/>
            <DiscreteObjectKeyFrame KeyTime="0:0:2" 
               Value="{Binding Source={StaticResource Frame3Image}"/>
            <!-- etc -->
        </ObjectAnimationUsingKeyFrames>
    </Storyboard>

因此,您必须向静态资源添加精灵,并运行 StoryBoard.

So, you have to add sprites to static resources, and run a StoryBoard.

这篇关于C# XAML Metro Image 动态源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆