【发布时间】:2014-08-21 19:10:51
【问题描述】:
我只是想在我的 Windows Phone 8.1 应用程序中创建一个简单的动画
我正在考虑通过在大约 300 毫秒的周期内更改 6 个图像来创建动画效果,最终留下使用 6-7 个图像的自定义动画。
但下面代码的问题是,它没有创建闪烁效果,它只显示第一张图像,然后显示最后一张。
我尝试增加时间段,但还是一样。
animationBg = new ObjectAnimationUsingKeyFrames();
storyboardBG = new Storyboard();
Storyboard.SetTarget(animationBg, imgMinuteBackground);
Storyboard.SetTargetProperty(animationBg, "Source");
storyboardBG.Children.Add(animationBg);
AddFrame(animationBg, "Images/clockbg2.png", 50);
AddFrame(animationBg, "Images/clockbg3.png", 100);
AddFrame(animationBg, "Images/clockbg4.png", 150);
AddFrame(animationBg, "Images/clockbg5.png", 200);
AddFrame(animationBg, "Images/clockbg6.png", 250);
AddFrame(animationBg, "Images/clockbg1.png", 300);
storyboardBG.Begin();
//AddFrame Function:
public void AddFrame( ObjectAnimationUsingKeyFrames animation, string strImagePath, int interval)
{
var keyframe = new DiscreteObjectKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(interval)),
Value = strImagePath
};
animation.KeyFrames.Add(keyframe);
}
我将“Source”更改为 new PropertyPath("Source"),它适用于 Windows Phone 7 应用程序。
【问题讨论】:
-
那么您是说
Storyboard.SetTargetProperty(animationBg, new PropertyPath("Source"));适用于 Windows 7,但不适用于 Windows 8?那很奇怪。我也会尝试使用这个:Storyboard.SetTargetProperty(animationBg, new PropertyPath(Image.SourceProperty)); -
它在 8.1 中不起作用
标签: c# animation windows-phone windows-phone-8.1