我正在使用图像列表框,它增加了千兆字节的内存使用量。我正在使用这个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都有像这样的图像路径 &#34; https://localhost:2673/SlideThumbnail/1272.png&#34;
答案 0 :(得分:1)
将ListBox
置于ScrollViewer
内会禁用 UI虚拟化,这意味着您的所有ListItems
都会立即在内存中创建。
尝试:
<Grid Grid.Row="0" Grid.Column="1">
<ListBox ItemsSource="{Binding Path=FilterImportSlideCollection}" ItemTemplate="{StaticResource slideItemTemplate}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" />
</Grid>
有关虚拟化的更多信息,请查看MSDN: