我喜欢在 XAML 中使用一个 Image 控件并交换 Source 来制作简单的动画Image
间隔1秒发送给其他人。
但当我这样做时,图像会闪烁。我使用这个代码(在Tick
的事件处理程序Timer
):
Uri uri = new Uri("ms-appx:/Sprites/Running/" + y++ + ".png",
UriKind.RelativeOrAbsolute);
BitmapImage textureBitmap = new BitmapImage(uri);
this.ImageHolder.Source = textureBitmap;
问题可能出在哪里?我应该缓存位图图像吗?
感谢您的帮助。
尝试声明一个故事板 http://msdn.microsoft.com/en-us/library/system.windows.media.animation.storyboard%28v=vs.90%29.aspx在你的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>
因此,您必须将精灵添加到静态资源,并运行 StoryBoard。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)