我试图在Windows phone8的ListBox中加载BitmapImages,但看到了奇怪的行为。第一次显示页面时,ListBox显示为空,但如果我返回,则返回到图像加载的页面。对我来说,这些图像似乎没有在需要的时候加载。这是我正在使用的代码(通过一个转换器):
BitmapImage img = null;
StreamResourceInfo res = Application.GetResourceStream(new Uri("/MyAssembly;component/Resource/images/myimage.png", UriKind.Relative));
Stream s = res.Stream;
using (s) {
img= new BitmapImage();
img.SetSource(s);
}
img.CreateOptions = BitmapCreateOptions.None;我尝试过使用create选项,但都没有用。
发布于 2013-02-03 04:27:51
这听起来像是在设置源之后视图没有刷新的原因。加载一个空的列表框。然后加载所有图像。什么也没显示出来!但是当你回到页面时,神奇的是!它们都在那里,因为整个视图都被重新绘制(现在使用图像源)。如果你在返回之前杀死了应用程序,你应该再次看到一个空的列表框,因为必须重置源代码。我不确定这在windows8中是如何工作的,但是你应该能够调用像listbox.RefreshView()这样的东西来强制它自己重绘。
发布于 2013-02-03 18:47:22
我实际上需要在我的ViewModel中的属性上调用RaisePropertyChanged来强制更新,as described here,但是你的回答给我指明了正确的方向。谢谢@teabaggs。
奇怪的是,当我有一个Pivot控件作为根元素时,这是有效的,但切换到Panorama肯定改变了事件顺序。
发布于 2014-07-16 15:44:22
使用: img.CreateOptions = BitmapCreateOptions.BackGround;
并在private void BitmapImage_ImageFailed(object sender, ExceptionRoutedEventArgs e) { BitmapImage img = new BitmapImage(); img.UriSource = new Uri("Your local Image", UriKind.Relative); }中分配您的本地镜像。无论如何,图像渲染需要时间,这是我到目前为止找到的最好最快的方法。
https://stackoverflow.com/questions/14664967
复制相似问题