【发布时间】:2010-08-30 10:43:08
【问题描述】:
我有一个包含大量图像控件的列表框。每个图像的来源都设置为远程服务器上的 URI。一次可以看到大约 20 张图像(面板是 VirtualizingStackPanel),每次滚动 ListBox 都需要几秒钟的时间来渲染图像,导致滚动非常缓慢。图片很小(每个 5-7K),不涉及调整大小。
当 Source 是本地 URI 时,性能很好。 图像由 nginx 服务器提供,并且几乎立即在浏览器中呈现。
我的问题是:
- 有没有更好的方法在 WPF 中显示这些图像?
- 如果这是最好的方法,我应该如何开始追踪瓶颈?
编辑:
ListBox 通过绑定到一个集合来填充。这是设置为 ListBox 的 ItemTemplate 的 DataTemplate 的 XAML:
<ListBoxItem>
<StackPanel>
<TextBlock Text="{Binding Path=Title}" />
<Image Width="50" Margin="0">
<Image.Source>
<BitmapImage UriSource="{Binding Path=ImageUri}" DecodePixelWidth="50" />
</Image.Source>
</Image>
</StackPanel>
</ListBoxItem>
【问题讨论】:
-
需要更多信息...您如何填写您的 ListBox ?通过显式添加 ListBoxItems 或使用绑定?请发布列表框的 XAML
标签: wpf performance