我有列表框绑定到ObservableCollection并使用文件名来显示图像

我的xaml是:
<Window x:Class="ThumbnailsView.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="578" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="55"/>
</Grid.RowDefinitions>
<ListBox Grid.Row="0" x:Name="ImageListbox"
ItemsSource="{Binding}"
Background="AliceBlue" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox Height="16" VerticalAlignment="Top" Margin="0,10,0,0"/>
<Image Margin="10,10,10,0" Height="64" Width="64" VerticalAlignment="Top">
<Image.Source>
<BitmapImage DecodePixelWidth="64" UriSource="{Binding Path=Name}"/>
</Image.Source>
</Image>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
<Button Grid.Row="1" Content="Get Images" Name="getImageBtn" Click="getImageBtn_Click" Width="100" Height="30"></Button>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
问题是,如果我有一个大型集合,它会加载整个图像并消耗大量的内存.如何最大限度地减少内存消耗?
启用 UI 虚拟化。然后UI控件将被回收并使用最少的内存。
您还可以加载缩略图而不是完整的照片。
一些可供阅读的资源:
http://www.codeproject.com/Articles/34405/WPF-Data-Virtualization /sf/ask/1011925281/ WPF列表框使用列表框 - UI 虚拟化和滚动 http://www.zagstudio.com/blog/497#.UQKxpScqb6U