【问题标题】:Performance of WPF Image renderingWPF 图像渲染的性能
【发布时间】:2010-08-30 10:43:08
【问题描述】:

我有一个包含大量图像控件的列表框。每个图像的来源都设置为远程服务器上的 URI。一次可以看到大约 20 张图像(面板是 VirtualizingStackPanel),每次滚动 ListBox 都需要几秒钟的时间来渲染图像,导致滚动非常缓慢。图片很小(每个 5-7K),不涉及调整大小。

当 Source 是本地 URI 时,性能很好。 图像由 nginx 服务器提供,并且几乎立即在浏览器中呈现。

我的问题是:

  1. 有没有更好的方法在 WPF 中显示这些图像?
  2. 如果这是最好的方法,我应该如何开始追踪瓶颈?

编辑:

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


【解决方案1】:

尝试绑定 ObservableCollection 中的图像,这会将 ImageSource 集合返回到 ItemTemplate 中的 Image。

HTH

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多