所以我有这个代码,它为数组中的每个字符串添加文件路径并将其用作图像框的文件路径,这是代码:
private async void Button7_Click(object sender, RoutedEventArgs e)
{
string[] images = new string[] { "Star_00001.png", "Star_00002.png", "Star_00003.png", "Star_00004.png", "Star_00005.png", "Star_00006.png", "Star_00007.png", "Star_00008.png"};
string path = "Assets/Star/";
foreach(string file in images)
{
string thepath = Path.Combine(path,file);
await Task.Delay(46);
BitmapImage Image = new BitmapImage();
Image.UriSource = new Uri(this.BaseUri, thepath);
StarImage.Source = Image;
}
}
现在每次将新图像加载到StarImage中时,它就会闪烁,据我所知它们无法阻止它,因为它是在图像框中加载新图像的效果,但有人知道任何停止这个并给出动画效果的替代方案?
答案 0 :(得分:0)
答案 1 :(得分:0)
试试这个:
private async void Button7_Click(object sender, RoutedEventArgs e)
{
string[] images = new string[] { "Star_00001.png", "Star_00002.png", "Star_00003.png", "Star_00004.png", "Star_00005.png", "Star_00006.png", "Star_00007.png", "Star_00008.png" };
string path = "Assets/Star/";
foreach (string file in images)
{
string thepath = Path.Combine(path, file);
await Task.Delay(46);
BitmapImage Image = new BitmapImage();
Image.BeginInit();
Image.UriSource = new Uri(this.BaseUri, thepath);
Image.CacheOption = BitmapCacheOption.OnLoad;
Image.EndInit();
StarImage.Source = Image;
}
}
答案 2 :(得分:0)
我试图解决这个问题已经绞尽脑汁了几个月,然后我找到了这篇文章。它帮我解决了这个问题!我无法理解为什么微软会不断改变语法来在windows中做事情。