带有图像的WPF列表框增加了内存
本文关键字:增加 内存 列表 WPF 图像 | 更新日期: 2023-09-27 18:09:44
我正在使用图像列表框,它将内存使用增加到千兆字节。我正在使用这个xaml.
<Grid Grid.Row="0" Grid.Column="1">
<ScrollViewer>
<ListBox ItemsSource="{Binding Path=FilterImportSlideCollection}" ItemTemplate="{StaticResource slideItemTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
</ScrollViewer>
</Grid>
模板是
<DataTemplate x:Key="slideItemTemplate" >
<Grid Width="100" Height="130" Margin="2 2 2 2" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Background="White" BorderBrush="Black" BorderThickness="1" Grid.Row="0" Panel.ZIndex="3" Canvas.Left="0" Canvas.Right="0">
<Image MinWidth="100" MinHeight="80" HorizontalAlignment="Center" Source="{Binding ImagePath, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"></Image>
</Border>
<TextBlock HorizontalAlignment="Left" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding Title}" Foreground="Black"/>
</Grid>
</DataTemplate>
每个ImagePath都有图像的路径"https://localhost: 2673/SlideThumbnail/1272. png"
将ListBox
放在ScrollViewer
中禁用UI虚拟化意味着所有的ListItems
都在内存中创建。
试题:
<Grid Grid.Row="0" Grid.Column="1">
<ListBox ItemsSource="{Binding Path=FilterImportSlideCollection}" ItemTemplate="{StaticResource slideItemTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
</Grid>
有关虚拟化的更多信息,请查看MSDN:
显示大型数据集