C# XAML Metro 图​​像动态源

标签 c# xaml windows-runtime winrt-xaml

我喜欢在 XAML 中使用一个图像控件制作简单的动画,并以 1 秒的间隔将 Image 的源交换到另一个。

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

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

this.ImageHolder.Source = textureBitmap;

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

感谢您的帮助。

最佳答案

尝试声明一个 StoryBoard在你的 xaml 中:

    <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>

因此,您必须将 Sprite 添加到静态资源,并运行 StoryBoard。

关于C# XAML Metro 图​​像动态源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12930661/

相关文章:

c# - 如何在通用 Windows 平台中检查互联网连接类型

c# - 德语特殊字符 Ää、Öö、Üü、ß 在 LiveLink 或 opentext 中显示不正确

c# - 当控件变得可见时以编程方式设置焦点

c# - 将 GridView 绑定(bind)到列表

windows-8 - 如果从 foursquare 传递到 Facebook,WebAuthenticationBroker 将挂起

c# - 在类型 '%0' 中找不到可附加属性 '%1'

c# - 您能否在 .NET 中的运行时更改动态 Web 引用的位置/端点?

c# - 如何在 .NET 中使用 Ruby 代码?

silverlight - “Is not recognized or is not accessible” 错误,创建表时

microsoft-metro - 当文件位于嵌套文件夹中时,是否可以从 Metro Apps 轻松读取/写入文件系统