我正在开发一个 WPF 应用程序,我需要在一个窗口中显示 7200 个图像。每个图像大小等于 300x300。我的代码“*.xaml”如下所示:
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Results}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Center" VerticalAlignment="Center" Height="180">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="180" />
<ColumnDefinition Width="180" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Margin="2">
<Label Content="{Binding Frame}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<Grid Grid.Column="1" Margin="2">
<Grid.Background>
<ImageBrush ImageSource="{Binding FrameImage}"/>
</Grid.Background>
<Image Source="{Binding FrameImage}"/>
</Grid>
<Grid Grid.Column="2" Margin="2">
<Grid.Background>
<ImageBrush ImageSource="{Binding FrameMatch}"/>
</Grid.Background>
<Image Source="{Binding FrameMatch}"/>
</Grid>
<Grid Grid.Column="3" Margin="2">
<Grid.Background>
<ImageBrush ImageSource="{Binding ObjMatch}"/>
</Grid.Background>
<Image Source="{Binding ObjMatch}"/>
</Grid>
<Grid Grid.Column="4" Margin="2">
<Image Source="{Binding ObjImage}"/>
</Grid>
<Grid Grid.Column="5" Margin="2">
<Label Content="{Binding Fitness}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
问题是程序消耗了很多内存。有可能克服这个问题吗?谁能给我一个解决方案?