1

我试图在 Windows Phone 8 的 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;

我试过尝试创建选项无济于事。

4

3 回答 3

1

听起来可能是在设置源后视图没有刷新。您加载一个空列表框。然后加载所有图像。什么都没有显示!但是当你回到页面时,神奇!它们都在那里,因为整个视图都被重绘了(现在有了图像源)。如果您在返回之前终止应用程序,您应该会再次看到一个空列表框,因为必须重置源。我不确定这在 Windows 8 中是如何工作的,但你应该能够调用 listbox.RefreshView() 之类的东西来强制它重新绘制自己。

于 2013-02-02T20:27:51.117 回答
0

我实际上需要调用RaisePropertyChangedViewModel 中的属性来强制更新,如此处所述,但您的回答为我指明了正确的方向。谢谢@teabaggs。

奇怪的是,当我将 Pivot 控件作为根元素时,这很有效,但切换到全景图一定会改变事件顺序。

于 2013-02-03T10:47:22.400 回答
0

使用这个: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); } 并在您的本地图像中分配 。无论如何,渲染图像需要时间,这是我迄今为止发现的最好和最快的方法

于 2014-07-16T07:44:22.220 回答