【问题标题】:Which wpf-control for massive image amount哪个 wpf-control 用于海量图像
【发布时间】:2015-09-27 10:47:54
【问题描述】:

我有 30000 张图片,现在我需要一个控件来显示图片(作为图片而不仅仅是文件路径)及其文件名。

需要某种分页,例如一页30张图,我想到了GridView?!

我有一个包含哈希表的列表(键:该图片的转义路径,值:图片名称),我有一个绑定到该哈希表的 GridView,但它只显示文件路径。

c#:

wordListView.ItemsSource = Hsh;// contains a property of Hahstable;

XAML:

      <DataGrid x:Name="wordListView" HorizontalAlignment="Left" VerticalAlignment="Top" Height="260" Width="645" Margin="10,156,0,0">
        <!--AutoGenerateColumns="False" ItemsSource="{Binding}">-->
        <!--<DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding ID}"   Header="ID" IsReadOnly="True" />
            <DataGridTextColumn Binding="{Binding Path}"  Header="Path"/>
            <DataGridTextColumn Binding="{Binding TimeStamp}"   Header="TimeStamp"/>
        </DataGrid.Columns>-->
    </DataGrid>

【问题讨论】:

  • 寻找 VirtualizingStackPanel 是个好主意。

标签: c# wpf xaml gridview wpf-controls


【解决方案1】:

如果您尝试一次将所有图像加载到内存中,性能将会很糟糕。因此,您可以使用虚拟化仅加载那些可见(或刚刚离开屏幕)的内容,并在用户滚动以使其可见时加载其他内容。

This answer 包含一些示例代码。简而言之,您需要将ItemsPanel 设置为VirtualizingStackPanel:

<ItemsControl
    VirtualizingStackPanel.IsVirtualizing="True"
    ScrollViewer.CanContentScroll="True"
    ItemsSource="{Binding MyItems}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Image Source="{Binding ImageSource}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

你可以阅读更多关于optimising performance on MSDN here的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-31
    • 2011-08-03
    • 2023-03-22
    • 2011-05-10
    • 2013-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多